使用SeleniumWebDriver和python跨URL导航

使用SeleniumWebDriver和python跨URL导航,python,unit-testing,selenium,selenium-webdriver,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').cl

我有一个要填写的表格和一个要在页面上按下的按钮,这会将我带到另一个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()

find\u element\u by\u css\u选择器
有一个选择器
。按钮。传递了按钮save
。您是否发送任何此类选择器以供单击?你能显示一些代码吗?@LearningNeverStops:当然,我会添加一个编辑器。你是说有两个不同的窗口吗?不,我想要的是,一旦我点击第一页的按钮,它就会在同一个窗口中加载第二个URL,然后从第一个转到第二个,就像你提交表单时会发生的那样。