I want to select text from the following html line:
<h3 data-reacid ='64'> text to select <h3>
I tried to use xpath. But for some reason, selenium can not find this element by xpath. I want to select the text by the 'data-reactid' attribute. I am not sure how to do this. I am using selenium with python.
Assuming 64 is a stable value and does not change for this particular element and the attribute name is data-reactid (and not the data-reacid - looks like a typo):
driver.find_element_by_xpath("//h3[@data-reactid = '64']").text
Equivalent CSS selector based solution:
driver.find_element_by_css_selector("h3[data-reactid=64]").text
Of course, you need to account for the possible timing issues and other situations like an element being inside an iframe. This is specific to your particular situation.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With