chrome web驱动程序- Selenium Chromedriver控制问题



我已经开始使用铬硒和它的工作很好,但当我打开一个新的选项卡的控制回到主选项卡和执行脚本,而不是新的选项卡。有没有人能帮我解决这个问题?

try this

 ArrayList<String> tabs2 = new ArrayList<String>(driver.getWindowHandles());
driver.switchTo().window(tabs2.get(tabs2.size()-1));
//Then do something
# Open the link in a new tab by sending key strokes on the element
# Use: Keys.CONTROL + Keys.SHIFT + Keys.RETURN to open tab on top of the stack 
url.send_keys(Keys.CONTROL + Keys.RETURN)
# Save the window opener (current window)
main_window = browser.current_window_handle
# Switch tab to the new tab
browser.find_element_by_tag_name('body').send_keys(Keys.CONTROL + Keys.TAB)
# Put focus on current window which will
browser.switch_to_window(browser.window_handles[1])
# do whatever you have to do on this page

最新更新