我使用webdriver点击iframe表单上的提交按钮。基本上是:
self.driver.find_element_by_css_selector("[name~='field_1']").clear()
self.driver.find_element_by_css_selector("[name~='field_1']").send_keys("123")
self.driver.find_element_by_css_selector("[name~='field_1']").send_keys(Keys.RETURN)
self.driver.switch_to_window(self.driver.window_handles[-1])
self.assertEqual(self.driver.current_url, "http://fake_address.com")
我也尝试过:
self.driver.find_element_by_css_selector("[name~='field_1']").clear()
self.driver.find_element_by_css_selector("[name~='field_1']").send_keys("123")
self.driver.find_element_by_css_selector("#submit-endslide").click()
self.driver.switch_to_window(self.driver.window_handles[-1])
self.assertEqual(self.driver.current_url, "http://fake_address.com")
和
self.driver.find_element_by_css_selector("[name~='field_1']").clear()
self.driver.find_element_by_css_selector("[name~='field_1']").send_keys("123")
self.driver.find_element_by_css_selector("#submit-endslide").submit()
self.driver.switch_to_window(self.driver.window_handles[-1])
self.assertEqual(self.driver.current_url, "http://fake_address.com")
我一直在:
Traceback (most recent call last):
File "test_ytplayer_smoke_form.py", line 198, in testSmallFormSubmission
self.driver.find_element_by_css_selector("[name~='field_1']").send_keys(Keys.RETURN)
File "/home/giant/our_player/lib/python2.7/site-packages/selenium/webdriver/remote/webelement.py", line 293, in send_keys
self._execute(Command.SEND_KEYS_TO_ELEMENT, {'value': typing})
File "/home/giant/our_player/lib/python2.7/site-packages/selenium/webdriver/remote/webelement.py", line 370, in _execute
return self._parent.execute(command, params)
File "/home/giant/our_player/lib/python2.7/site-packages/selenium/webdriver/remote/webdriver.py", line 166, in execute
self.error_handler.check_response(response)
File "/home/giant/our_player/lib/python2.7/site-packages/selenium/webdriver/remote/errorhandler.py", line 164, in check_response
raise exception_class(message, screen, stacktrace)
TimeoutException: Message: u'Selenium took too long to run your command.
然后 WebDriverException:消息:u'由于先前的错误,此作业已完成。
无论选择哪种方法,点击提交按钮时总会出现超时; (我已经尝试将超时时间增加到300)
注意:当我观看测试运行时,单击提交按钮并打开一个新选项卡,但由于例外情况,测试将永远不会通过。
答案 0 :(得分:1)
Chrome V28似乎存在导致此问题的浏览器特定问题;我更新到最新的Chrome V35浏览器版本,这似乎已经解决了
答案 1 :(得分:0)
正如我的评论所说,我们需要更多信息,但评论很难编辑,所以我在这里添加更多信息:
找到变量时将元素存储在变量中,如:
field_1 = self.driver.find_element_by_css_selector(“[name~ ='field_1']”)
)
field_1.clear()
field_1.send_keys( “123”)
submit = self.driver.find_element_by_css_selector(“#submit-endslide”)
submit.click()
但是尝试直接使用WebElementDrive和ExpectedConditions而不是驱动程序方法。