英文:
Can not take a selector(Xpath) of "Account settings button" and "find my iPhone" in iCloud
问题
我需要在iCloud.com上点击“帐户设置”和“查找我的iPhone”按钮(不是同时点击)。但是我的选择器都不起作用。
页面上似乎没有框架,但Xpath表达式不匹配。
步骤:
- 登录iCloud帐户
- 查找“帐户设置”和“查找我的”按钮
这是我现在正在使用的:
对于“查找”按钮:
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();
我感激任何帮助。如果我的问题很愚蠢,请原谅,我刚开始学习。
英文:
I need to click "Account settings" and "find my iPhone" buttons on iCloud.com (not at the same time). But none of my selectors working.
Looks like there are no frame on-page, but Xpaths not matching.
Steps:
- Sign in to iCloud account
- Find elements "Account setting" and "Find my" buttons
This is what I'm using now:
For Find button:
WebElement settings=wait.until(ExpectedConditions.
elementToBeClickable
(By.xpath("//div[@class='user-name-with-chevron']")));
settings.click();
For Account settings:
WebElement settings = wait.until(ExpectedConditions.
elementToBeClickable(By.xpath
("//div[@class='cw-button symbol-button link-button']")));
settings.click();
I appreciate any help.
sorry if my questions stupid, just start to learn.
答案1
得分: 0
我相信您可能在登录后错过了切换回默认内容。
我尝试了下面的代码,对我起作用:
driver.findElement(By.id("sign-in")).click();
driver.switchTo().defaultContent(); // 切换回默认内容
driver.findElement(By.cssSelector("div.cw-button.symbol-button.link-button")).click(); // 点击帐户设置
在从 iframe 切换回默认内容后,我能够在页面上定位任何网页元素。
希望对您有所帮助
英文:
I believe you might have missed to switch back to default content after log in.
I tried below code and it worked for me :
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
After switching from iframe to default content i was able to locate any webelement on page.
Hope this helps
专注分享java语言的经验与见解,让所有开发者获益!
评论