简体   繁体   中英

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.

The information which browser you are using would be very interesting. And the webdriver doesn't need to control the visbile Tab. So i wouldn't let the Browser change the Tab and I would use the "switchTo" Method of the webdriver.
More information to this topic is here .

As @Kikkirej mentuined, i see no reason to use sendKeys to switch between opened tabs. 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM