Home > Software design >  Get error [object Text]. It should be an element
Get error [object Text]. It should be an element

Time:10-01

Trying to get the text from the div with xPath. Finds information in the browser good, but when i try to run with an idea than i get error:"is: [object Text]. It should be an element."

       List<WebElement> priceGameWebElement =  webDriver.findElements(By.xpath("//div[contains(@class,'search_price')]"  
            "/text()[normalize-space()][1]"));

What do I need to do to make everything work?

CodePudding user response:

You can "interrupt" your query before the /text()... part like this:

List<WebElement> priceGameWebElement =  webDriver.findElements(By.xpath("//div[contains(@class,'search_price')]"));

Then you should get a List<WebElement> which contains the elements with the text() nodes for further distinction. They could probably be queried with the .getText() function.

  • Related