简体   繁体   English

无法通过xpath查找元素以进行选择

[英]Cant find element by xpath to select

Hi im having serious issues trying to locate this element using an xpath: 嗨,我在尝试使用xpath定位此元素时遇到严重问题:

class="accountSettingsTextBase_1u09j40-o_O-accountSettingsItemText_10y8axf" aria-current="false" href="/account/signin">Log In

I've tried: 我试过了:

"//*[contains(text(),'Log In')]"

and also the actual xpath: 以及实际的xpath:

//*[@id='root']/div/header/div[3]/nav/ul/li[1]/a

as well as link text which still won't work, any ideas?? 以及仍然无法使用的链接文字,有什么想法吗?

The anchor tags are missing from the HTML by the way, as it was just showing "Log In" with them added in 顺便说一下,HTML缺少锚标记,因为它只是显示“登录”并添加了它们

Full HTML: Full HTML 完整HTML: 完整HTML

Possible xpaths : 可能的xpath:

//a[@href='/account/signin']

OR 要么

//a[contains(.,'Log In')]

OR 要么

Try using Css selector : 尝试使用Css选择器:

a[class^='accountSettingsTextBase_' ][class*='accountSettingsItemText']
//[contains(text(),'Log In')]

您缺少了一些东西:

//*[contains(text(),'Log In')]

Why don't you use 你为什么不使用

driver.findElement(By.linkText("Log In"))

or 要么

driver.findElement(By.partialLinkText("Log In"))

since the element is an anchor tag? 由于元素是anchor标记?

Please add the explicit wait and then check 请添加明确的等待,然后检查

WebDriverWait wait=new WebDriverWait(driver,20);
wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//*[contains(text(),'Log In')]")));
driver.findElement(By.xpath("//*[contains(text(),'Log In')]")).click();

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

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