使用selenium webdriver,python浏览URL

时间:2015-04-12 10:58:49

标签: python unit-testing selenium selenium-webdriver

我有一个要填写的表单和一个要在页面上按下的按钮,该按钮会将我带到另一个URL(表单完成后),并且该页面在点击时有另一个按钮,表单中填写的结果将被下载到一个安排得很好的pdf格式。我在点击第一个URL的按钮时,当前很难导航到第二个URL,也就是说,当我尝试选择任何第二个窗口的组件时,我收到以下错误。

Traceback (most recent call last):
    self.driver.find_element_by_css_selector('.buttons.button-save').click()
  File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/remote/webdriver.py", line 376, in find_element_by_css_selector
    return self.find_element(by=By.CSS_SELECTOR, value=css_selector)
  File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/remote/webdriver.py", line 664, in find_element
    {'using': by, 'value': value})['value']
  File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/remote/webdriver.py", line 175, in execute
    self.error_handler.check_response(response)
  File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/remote/errorhandler.py", line 166, in check_response
    raise exception_class(message, screen, stacktrace)
NoSuchElementException: Message: Unable to locate element: {"method":"css selector","selector":".buttons.button-save"}

在我尝试点击第二页的按钮之前,我也试过使用显式等待,但它没有用。 任何帮助将不胜感激,谢谢!

编辑: 当我在点击第一页上的按钮并保存图像后截取屏幕截图时,我只能看到第一个URL的屏幕截图。此外,我添加了一个明确的等待,以找到第二个URL中的元素的存在,我得到了以下回溯

Traceback (most recent call last):
    EC.presence_of_element_located((By.ID, "button-save")))
  File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/support/wait.py", line 75, in until
    raise TimeoutException(message, screen, stacktrace)

相关守则,

#Clicking the save button
self.driver.find_element_by_css_selector('.submit.submit.submit').click()
#Waiting to click on the button in second URL
element = WebDriverWait(self.driver, 10).until(
    EC.presence_of_element_located((By.ID, "button-save")))
#Saving the screenshot to check in which window it is
self.driver.save_screenshot('file2.png')
#Click the button on the second page
self.driver.find_element_by_css_selector('.buttons.button-save').click()

0 个答案:

没有答案