[英]Unable to locate elements on a website , i tried all the locators but I get the error "No such element" . I am a self taught beginner to Automation
driver.findElement(By.linkText("Log out"));
Something like that should work, you should provide the page html for a better response.类似的东西应该可以工作,您应该提供页面 html 以获得更好的响应。
My response is based on the fact that in your first try you are saying text='Log out'.我的回答是基于这样一个事实,即在您第一次尝试时您说的是 text='Log out'。 findElement in selenium works with locatorStrategies (By.cssSelector/By.linkText...) the one that i used (linkText) search in all the anchor tags that are found in the pages () and analyze the text inside the tag, if the text is matched the driver will find the element. selenium 中的 findElement 与我使用的 locatorStrategies (By.cssSelector/By.linkText ...) 一起使用 (linkText) 在页面 () 中找到的所有锚标签中搜索并分析标签内的文本,如果文本匹配驱动程序将找到该元素。
Let me know if it works, otherwise provide me the web page html snippet.让我知道它是否有效,否则请提供 web 页面 html 片段。
I've seen the actual screen, you must change Log out with Inbox我已经看到了实际的屏幕,您必须使用 Inbox 更改 Log out
driver.findElement(By.linkText("Inbox"));
Given the HTML:鉴于 HTML:
<a href="/cacApp/Main/INBOX" title="View the Inbox" target="main">Inbox</a>
You need to take care of a couple of things here as follows:您需要注意以下几点:
:contains("text")
method在cssSelector中不支持:contains("text")
方法text()
在xpath中,您需要使用text()
To identify the element you can use either of the following locator strategies :要识别元素,您可以使用以下任一定位器策略:
Using linkText :使用链接文本:
WebElement element = driver.findElement(By.linkText("Log out"));
Using cssSelector :使用cssSelector :
WebElement element = driver.findElement(By.cssSelector("a[href$='INBOX'][title='View the Inbox']"));
Using xpath :使用xpath :
WebElement element = driver.findElement(By.xpath("//a[text()='Inbox' and @title='View the Inbox']"));
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.