繁体   English   中英

如何通过Java Selenium中的XPath标识文本元素为Google登录

[英]How to identify the element with text as Sign in with Google through xpath in java selenium

我正在为redbus应用程序执行自动化,但是我正在使用firebug查找Web元素,它将突出显示firefox浏览器,但是在chrome浏览器中不起作用。

请查看以下屏幕截图: Redbus网站链接

  • 步骤1打开redbus应用程序URL = https://www.redbus.in/
  • 步骤2点击“帐户”模块
  • 步骤3点击“签署”或“注册”链接

我的XPath是:

.//*[@id='g-signin2']//span[text()='Sign in with Google']

Chrome浏览器屏幕截图:无法识别webElement

Google注册链接位于iframe中,为了与frame / iframe内部的元素进行交互,您需要将Web驱动程序的焦点更改为该特定框架。

在您的情况下,您该如何做:

driver.switchTo.frame("//iframe[@class='modalIframe']")  

然后,您可以与通过Google登录进行交互。

WebElement signupButton = new WebDriverWait(driver, 10).until(ExpectedConditions.elementToBeClickable(By.xpath("//span[contains(@id,'signed') and text()='Sign in with Google']")))  
signupButton.click();  

HTH!

识别并调用文本为的元素上的click() ,方法是使用Google登录 ,因为该元素位于中。 因此,对于这两种情况,您都必须引入WebDriverWait ,一次使框架可用 ,再一次使所需元素可单击,然后可以使用以下解决方案:

new WebDriverWait(driver, 10).until(ExpectedConditions.frameToBeAvailableAndSwitchToIt(By.xpath("//iframe[@class='modalIframe' and @src='/account?pageName=Home&noReload=noReload']")));
new WebDriverWait(driver, 10).until(ExpectedConditions.elementToBeClickable(By.xpath("//span[@class='abcRioButtonContents']//span[normalize-space()='Sign in with Google']"))).click();

看起来登录弹出窗口在iframe标记内可用。 首先,如下所示导航到该特定框架,然后在xpath步骤中添加符号。

driver.switchTo().frame(0);

您在这里拥有的是模态框架,您应该首先打开它,并对元素执行操作:

driver.switchTo().frame("modalIframe");

也许这:

driver.switchTo().activeElement()

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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