I'm facing a small issue while try to get values from a web page using python and Selenium. First of all I must say, the person who wrote the webpage is not written using the best way. There are few models in the html file and I'm trying to get values from the currently opened one.
for modal in driver.find_elements_by_class_name("modal"):
if modal.value_of_css_property("display") == "block":
location = modal.find_element_by_tag_name("p").get_attribute("textContent")
phValue = modal.find_element_by_xpath("//table//tr[3]//td[2]").find_element_by_tag_name("p").get_attribute("textContent")
print(location) // giving me the correct value
print(phValue) // giving me the wrong value
As you can see here I'm getting all the modals and try to get the active modal using the display css property. then I'm getting the active modal's paragraph tag value as location. It is working as I need and giving me the paragraph tag value of the currently opened modal. Every modal has a table, inside the table, I'm getting some values. But phValue gives me the value of currently UNOPENED model's values instead of the Opened one. any Idea how to fix this?
PS- The wrong value is in the First model and it is not opened currently.
Thanks for the help fellas.
Aucun commentaire:
Enregistrer un commentaire