简体   繁体   English

在Selenium Webdriver中从一个选项卡导航到另一个选项卡后,按钮的xpath不起作用,如何使它起作用?

[英]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.

相关问题 Xpath不适用于Selenium - Xpath does not work with Selenium 什么是setElementConverter以及它在Selenium WebDriver中的工作原理? - What is setElementConverter and how does it work in Selenium WebDriver? 使用Selenium Webdriver在新选项卡上打开页面后如何处理打开的页面? - How to work on opened page after opening it on new tab using selenium webdriver? 如何使用Java使两个GUI滑块彼此独立工作? - How can I make two GUI sliders work independently from one another using Java? 如何在Selenium WebDriver中动态更改xpath? - How can I change my xpath dynamically in Selenium WebDriver? 这个简单的Java / Selenium WebDriver代码如何工作 - How does this simple Java/Selenium WebDriver Code work 我如何在Selenium WebDriver中获得带有TestNG框架的测试报告? - How can i get Test Report with TestNG frame work with Selenium WebDriver? 在Selenium WebDriver中打开新标签后,如何使其在浏览器中显示为可见/活动标签? - After opening a new tab in Selenium WebDriver, how to make it the visible/active tab in my browser? 有人可以帮助我如何使另一个框架中的按钮工作吗? - can someone help me how to make the button from another frame work? 如何在 selenium webdriver 中定义具有多个类的按钮的 xpath - How to define xpath of button having more than one classes in selenium webdriver
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM