我需要在多个Firefox选项卡上运行不同的任务。每个选项卡将在应用程序启动时加载不同的URL。一个进程将在选项卡上运行,转到下一个,运行下一个选项卡,转到下一个选项卡,等等。我的问题是,当我返回到在应用程序启动时打开的选项卡时,必须运行driver.get(url)以便再次控制该标签。有没有一种方法可以控制标签,而无需再次运行driver.get(url)来控制页面?
我的代码示例:
main(){
int ix = 1;
while(ix <= numberOfTabstoRun){
driver.get(url[ix]);
if(ix != numberOfTabstoRun){
openNewTab(driver);
}
ix++;
}
/**THIS WONT WORK - can't control next tab**/
while(true){
//run process on open tab
nextTab(driver);
}
/**I am forced to do this**/
int x = 1;
while(true){
driver.get(url[x]);
//run process on open tab
nextTab(driver);
x++;
}
}
private void openNewTab(WebDriver driver){
new Actions(driver).sendKeys(Keys.chord(Keys.CONTROL, "t")).perform();
}
private void nextTab(WebDriver driver){
new Actions(driver).sendKeys(Keys.chord(Keys.CONTROL, Keys.TAB)).perform();
}
发送时,需要将驱动程序切换到新目标ctrl+tab
。
private void nextTab(WebDriver driver){
new Actions(driver).sendKeys(Keys.chord(Keys.CONTROL, Keys.TAB)).perform();
driver.switchTo().defaultContent();
}
有关更多详细信息,请访问http://design-interviews.blogspot.com/2014/11/switching-between-tabs-in-same-browser-window.html
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句