[英]After navigating from one tab to another in selenium webdriver, the xpath for a button does not work, how can I make it work?
// opening the base URL
driver1.get(baseUrl+"/");
// opening a new tab
driver1.findElement(By.cssSelector("Body")).sendKeys(Keys.COMMAND + "t");
driver1.get("my URL");
// getting back to the first tab
driver1.findElement(By.cssSelector("body")).sendKeys(Keys.COMMAND, Keys.SHIFT, "{");
// I want to signup by clicking the sign up button
driver1.findElement(By.xpath("/html/body/div[1]/header/div[2]/button")).click();
The error that I get after running is : "Error communicating with the remote browser. It may have died." 运行后出现的错误是:“与远程浏览器通信时出错。它可能已经死亡。”
But when I run the same code without the navigation, the button click works fine, then it means there is no problem with the xpath. 但是,当我在没有导航的情况下运行相同的代码时,单击按钮的效果很好,那么这意味着xpath没问题。
The information which browser you are using would be very interesting. 您正在使用哪个浏览器的信息将非常有趣。 And the webdriver doesn't need to control the visbile Tab.
而且,webdriver不需要控制可见选项卡。 So i wouldn't let the Browser change the Tab and I would use the "switchTo" Method of the webdriver.
因此,我不会让浏览器更改选项卡,而是使用webdriver的“ switchTo”方法。
More information to this topic is here . 有关此主题的更多信息,请参见此处 。
As @Kikkirej mentuined, i see no reason to use sendKeys to switch between opened tabs. 正如@Kikkirej所说,我认为没有理由使用sendKeys在打开的选项卡之间进行切换。 Use Selenium instead, it is a much better approach.
改用硒,这是一种更好的方法。
Edit: in addition, try to provide more information, especially the most basic part - the browser you are automating. 编辑:此外,请尝试提供更多信息,尤其是最基本的部分-您正在自动化的浏览器。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.