我是硒和硒的新手。蟒蛇。 我安装了python 3.4.1&硒webdriver。使用selenium ide创建脚本并导出到python webdriver。 Firefox版本 - 31.0 系统配置:窗口 - 32位
脚本: 来自selenium import webdriver 来自selenium.webdriver.common.by导入 来自selenium.webdriver.common.keys导入密钥 来自selenium.webdriver.support.ui import选择 来自selenium.common.exceptions import NoSuchElementException import unittest,time,re
class Test(unittest.TestCase):
def setUp(self):
self.driver = webdriver.Firefox()
self.driver.implicitly_wait(30)
self.base_url = "https://www.gmail.com/"
self.verificationErrors = []
self.accept_next_alert = True
def test_(self):
driver = self.driver
driver.get(self.base_url)
driver.find_element_by_id("Email").clear()
driver.find_element_by_id("Email").send_keys("shivart")
driver.find_element_by_id("Passwd").clear()
driver.find_element_by_id("Passwd").send_keys("test12")
driver.find_element_by_id("signIn").click()
driver.find_element_by_css_selector("span.gb_2").click()
driver.find_element_by_id("gb_71").click()
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):
# self.driver.quit()
# self.assertEqual([], self.verificationErrors)
if __name__ == "__main__":
unittest.main()
运行脚本时我得到以下错误。
追踪(最近一次通话): 在test_中的文件“C:\ test.py”,第20行 driver.find_element_by_id( “电子邮件”)。send_keys( “shivart.rt”) 文件“C:\ Python34 \ lib \ site-packages \ selenium \ webdriver \ remote \ webelement.py”, 第293行,在send_keys中 self._execute(Command.SEND_KEYS_TO_ELEMENT,{'value':输入})
File "C:\Python34\lib\site-packages\selenium\webdriver\remote\webelement.py",
line 370, in _execute
return self._parent.execute(command, params)
文件“C:\ Python34 \ lib \ site-packages \ selenium \ webdriver \ remote \ webdriver.py”,l ine 173,执行中 self.error_handler.check_response(回复)
File "C:\Python34\lib\site-packages\selenium\webdriver\remote\errorhandler.py"
, line 164, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.WebDriverException:消息:'组件返回失败 输入代码:0x80004003(NS_ERROR_INVALID_POINTER)[nsINativeKeyboard.sendKeys]'