I have the following code to find some buttons that I need to click using Selenium and Python:
elems = driver.find_elements_by_xpath('//div[@id = "RangeViewer"]//button[starts-with(@class,"range")]')
print(len(elems))
print("\n")
for e in elems:
print("ID attrib: " + e.get_attribute("id"))
print("text: " + e.text )
print("class attrib: " + e.get_attribute("class"))
print(e.get_attribute("xpath"))
# e.click()
time.sleep(5)
print("_________\n")
And I get the following print out:
4
ID attrib: Fold 2.2
text: Fold 2.2
0.58
class attrib: range-button
None
_________
ID attrib: Call 8
text: Call 8
0.23
class attrib: range-button active-tab
None
_________
ID attrib: Raise to 22.6
text: Raise to 22.6
0.15
class attrib: range-button
None
_________
ID attrib: All-In 100
text: All-In 100
0.04
class attrib: range-button
None
_________
So all the elements that I want are there but as soon as I uncomment e.click() I get either stale element error or NoSuchElementError from Selenium. The behaviour is erratic, sometimes it clicks on 2 elements before reporting the error, sometimes it exits after first click.
I do not get it, what am I doing wrong?
Also, why do I get None from e.getattribute("xpath")? Shouldn't every element have an xpath?