Find element that the ID is generated randomly

Asked

Viewed 154 times

0

I have a situation that id, always updating randomly.. and without an apparent order making it possible for me to use find_element_by_id

the component is as follows::

<table id="treeview-2234-record-879" data-boundview="treeview-2234" data-recordid="879" data-recordindex="0" class="x-grid-item x-grid-item-selected" cellpadding="0" cellspacing="0" style="width:100%;">

What have I ever tried?

  • Use recordid, but it repeats in some cases
  • By class_name there are other components with the same class
  • Of course, by the id.. which as I explained updates in all refresh and is Random
  • I tried for the element text, but to no avail.
  • At the root of treeview-2234, unsuccessfully.

I’m more of a victim of EXT, some light?

1 answer

1


As the implementation of Selenium for python allows you to use CSS and XPATH selectors this is trivial, examples:

# XPATH

table = driver.find_element_by_xpath("//table[@data-recordid='879']")

# CSS

table = driver.find_element_by_css_selector("table[data-recordid='879']")
  • also applies the data-recordindex='0'? can’t test at the moment.. but it works?

  • It will work for any valid CSS|XPATH selector. If you want to test if the selector works "manually" before running Selenium just open your browser console on the page you are testing and run something like this: document.querySelectorAll("table[data-recordid='879']"); // CSS $x("//table[@data-recordid='879']"); // XPATH, só funciona no chrome

  • I’ll try, thank you for the answer.

  • If solving your problem would be good you mark my answer as correct ;)

  • For sure I will,

  • There are more than one component with the same data-recordid, how can I get around that?

Show 1 more comment

Browser other questions tagged

You are not signed in. Login or sign up in order to post.