我已经开始使用chrome作为selenium并且工作正常但是当我打开一个新选项卡时,控件返回到主选项卡并在那里执行脚本而不是新选项卡。有人可以帮助我解决这个问题。
答案 0 :(得分:0)
试试这个
ArrayList<String> tabs2 = new ArrayList<String>(driver.getWindowHandles());
driver.switchTo().window(tabs2.get(tabs2.size()-1));
//Then do something
答案 1 :(得分:0)
# 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