简体   繁体   中英

Xpath Select Element Selenium

i am trying get a element through selenium with code:

WebElement a = driver.findElement(By.xpath("//div[@id=':r6']/span/text()"));

using this same expression on a firefox plugin, the element is find, but in selenium(java code) this way the element is not found, someone can me help

The command that you might need is: "AllowNativeXPath" - then just use the Xpath (either via Xpather or after 'inspecting element')to identify your element. Sometimes, though... there's still an issue where Selenium does not 'see' elements described with an Xpath while running a script, but when users click the 'Find' button... Selenium has no trouble at all. I usually take the focus up a level and down a level before any commands that Selenium has trouble finding the elements for... and it works well thereafter. It's ugly and very NOT elegant... but it works.

Selenium uses it's OWN Xpath interpreter... and the one native to your browser might be better in some cases.

You can try this instead:

WebElement a = driver.findElement(By.xpath("//div[@id=':r6']/span")).getText();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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