1

this is the HTML code for the element

I need to get the text inside the element and I am using Inner HTML, in Java Selenium but all the xpaths and css selectors written by me, are wrong, can you help me to get the right one please? Also it turn out, that the element is within a frame, how can i assess an element in a frame?

this is the element

  WebElement Element = obj.findElement(By.xpath("//*[@id=\"container\"]/div/div[2]/span"));

            System.out.println(Element.getAttribute("innerHTML"));

this is the way that should help me to get the text

  • Is this a table? Can you share the whole DOM of this table? Tables require filtering and the understanding of the whole table's DOM. – João Farias Mar 16 at 9:57
  • this is not a table, but a number for uninstall rate for some certain app, i will post the photo of the element asap – anmoruk15 Mar 16 at 10:08
1

The Xpath "//*[@id=\"container\"]/div/div[2]/span" that you wrote is unstable due to the /div/div[2] part. When using a chain of div or indexed div, if something changes in the DOM in that area, your element will not be found anymore. The xpath below are more specific to the element that you are looking for.

  • //div[contains(@class, 'layout-row')]/span
  • //div[@id='container']/div[contains(@class, 'layout-row')]/span
  • thanks for your reply, I have tried your versions, nothing works, and it turned out, that this element is within a frame, may be that changes the situation? – anmoruk15 Mar 18 at 8:31
  • Try to switch to that frame first. This post offers more details on this: stackoverflow.com/questions/20069737/… – return Mar 19 at 8:59
0

Try this CSS

#container div.layout-row span

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.