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