我是python编程的新手,请多多包涵!
我最近下载了Python 3.7.3,并使用pip成功安装了许多附加模块(包括Numpy,Scipy,Matplotlib,Gamepy,Xlwings和 Selenium )。
>我正在尝试使用Selenium编写一个非常简单的.py
文件,以导航至google并进行非常简单的搜索,然后关闭标签页(我使用Katalon
记录的代码)插件,以及我在下面遇到的问题!)
# -*- coding: utf-8 -*-
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support.ui import Select
from selenium.common.exceptions import NoSuchElementException
from selenium.common.exceptions import NoAlertPresentException
import unittest, time, re
class AppDynamicsJob(unittest.TestCase):
def setUp(self):
# AppDynamics will automatically override this web driver
# as documented in https://docs.appdynamics.com/display/PRO44/Write+Your+First+Script
self.driver = webdriver.Firefox()
self.driver.implicitly_wait(30)
self.base_url = "https://www.google.com/"
self.verificationErrors = []
self.accept_next_alert = True
def test_app_dynamics_job(self):
driver = self.driver
driver.get("https://www.google.com/")
driver.find_element_by_name("q").clear()
driver.find_element_by_name("q").send_keys("Test search")
driver.find_element_by_name("q").send_keys(Keys.ENTER)
driver.close()
def is_element_present(self, how, what):
try: self.driver.find_element(by=how, value=what)
except NoSuchElementException as e: return False
return True
def is_alert_present(self):
try: self.driver.switch_to_alert()
except NoAlertPresentException as e: return False
return True
def close_alert_and_get_its_text(self):
try:
alert = self.driver.switch_to_alert()
alert_text = alert.text
if self.accept_next_alert:
alert.accept()
else:
alert.dismiss()
return alert_text
finally: self.accept_next_alert = True
def tearDown(self):
# To know more about the difference between verify and assert,
# visit https://www.seleniumhq.org/docs/06_test_design_considerations.jsp#validating-results
self.assertEqual([], self.verificationErrors)
if __name__ == "__main__":
unittest.main()
E ================================================== ===================错误:test_untitled_test_case(主要 .UntitledTestCase) -------------------------------------------------- --------------------追溯(最近一次通话):文件 “ C:\ Users \ jer_m \ AppData \ Local \ Programs \ Python \ Python37 \ lib \ site-packages \ selenium \ webdriver \ common \ service.py”, 第76行,开始时 stdin = PIPE)文件“ C:\ Users \ jer_m \ AppData \ Local \ Programs \ Python \ Python37 \ lib \ subprocess.py”, 第775行,在 init 中 restore_signals,start_new_session)文件“ C:\ Users \ jer_m \ AppData \ Local \ Programs \ Python \ Python37 \ lib \ subprocess.py”, _execute_child中的第1178行 startupinfo)FileNotFoundError:[WinError 2]系统找不到指定的文件
在处理上述异常期间,发生了另一个异常:
回溯(最近通话最近):文件 setUp中的第12行,“ C:/Users/jer_m/AppData/Local/Programs/Python/Python37/Scripts/Test.py” self.driver = webdriver.Firefox()文件“ C:\ Users \ jer_m \ AppData \ Local \ Programs \ Python \ Python37 \ lib \ site-packages \ selenium \ webdriver \ firefox \ webdriver.py”, 第164行, init self.service.start()文件“ C:\ Users \ jer_m \ AppData \ Local \ Programs \ Python \ Python37 \ lib \ site-packages \ selenium \ webdriver \ common \ service.py”, 第83行,开始时 os.path.basename(self.path),self.start_error_message)selenium.common.exceptions.WebDriverException:消息:“ geckodriver” 可执行文件必须位于PATH中。
-------------------------------------------------- -----------------------在0.009秒内进行了1次测试
失败(错误= 1)
我引用的大多数python文件都是默认文件,它们是Selenium
模块的一部分,因此我不确定路径可能如何更改(例如,我注意到{{1 }}似乎是特定于实际的驱动程序的,因此它位于单独的浏览器文件夹中。)
我打算将Firefox文件夹中的service.py
文件复制到“普通”文件夹中。
此外,service.py
文件引发错误,并且由于它们是库文件,因此我想它们不会引起问题。有人遇到过这些错误吗?没解决这个问题吗?
subprocess.py
中的代码块是;
subprocess.py
和
self._execute_child(args, executable, preexec_fn, close_fds,
pass_fds, cwd, env,
startupinfo, creationflags, shell,
p2cread, p2cwrite,
c2pread, c2pwrite,
errread, errwrite,
restore_signals, start_new_session)