【问题标题】:Can not take a selector(Xpath) of "Account settings button" and "find my iPhone" in iCloud无法在 iCloud 中选择“帐户设置按钮”和“查找我的 iPhone”的选择器(Xpath)
【发布时间】:2020-07-18 02:09:51
【问题描述】:

我需要点击 iCloud.com 上的“帐户设置”和“查找我的 iPhone”按钮(不是同时)。但是我的选择器都没有工作。 页面上似乎没有框架,但 Xpath 不匹配。

步骤:

  1. 登录 iCloud 帐户
  2. 查找元素“帐户设置”和“查找我的”按钮

这是我现在使用的: 对于查找按钮:

WebElement settings=wait.until(ExpectedConditions.
elementToBeClickable
(By.xpath("//div[@class='user-name-with-chevron']")));
settings.click();

对于帐户设置:

 WebElement settings = wait.until(ExpectedConditions.
 elementToBeClickable(By.xpath
 ("//div[@class='cw-button symbol-button link-button']")));
 settings.click(); 

感谢您的帮助。 抱歉,如果我的问题很愚蠢,请开始学习。

html page

【问题讨论】:

    标签: java css selenium xpath automation


    【解决方案1】:

    我相信您在登录后可能错过了切换回默认内容。 我尝试了下面的代码,它对我有用:

    driver.findElement(By.id("sign-in")).click();
    driver.switchTo().defaultContent(); //switch to default content 
    driver.findElement(By.cssSelector("div.cw-button.symbol-button.link-button")).click(); //click on Account settings
    

    从 iframe 切换到默认内容后,我能够找到页面上的任何 web 元素。 希望这会有所帮助:)

    【讨论】:

    • 非常感谢您的回答,是的,它现在正在工作))
    • 嗨,您能否为答案投票,以便其他人在遇到类似问题时也能从中受益。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-09-29
    • 2016-05-25
    • 1970-01-01
    • 2019-10-11
    • 2016-05-13
    相关资源
    最近更新 更多