如何在Selenium Chrome Python中从第二个选项卡打开第三个选项卡

时间:2018-09-06 19:53:12

标签: python-3.x selenium-webdriver selenium-chromedriver

我正在使用此代码在Chrome驱动程序中打开第二个标签。我无法弄清楚如何从第二个选项卡打开第三个选项卡。希望有人可以帮忙。

def open_in_new_window(self,url):
 try:
         self.driver.execute_script('window.open("{}", "_blank");'.format(url))        
         current_window = self.driver.current_window_handle
         new_window = [window for window in self.driver.window_handles if window != current_window][0]
         self.driver.switch_to.window(new_window)             
         time.sleep(10)
         self.driver.execute_script("window.scrollTo(0, document.body.scrollHeight);")
         self.driver.execute_script("window.scrollTo(0, document.body.scrollHeight);")
         time.sleep(2)
         source=self.driver.page_source
         self.driver.close()
         self.driver.switch_to.window(current_window)
  except Exception as e:
        print(e)
        self.open_in_new_window(url)

0 个答案:

没有答案