我正在使用此代码在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)