0

I am attempting to select an option form a dropdown menu using selenium in python but kept getting an error that says "Message: Could not locate element with visible text: Active - Milestone VUL-G"

I figured out that the issue is likely that in the HTML for the websource, there are two dropdowns with the exact same coding

Here is my python code:

enter image description here

When I try this, I believe it goes to the FIRST dropdown, and so it cant find the option I am looking for because its the wrong dropdown. How do I get it to look for the 2nd dropdown in the website? There seems to be a Primary site and Secondary site

enter image description here

Thanks!

0

In its current format, I think forming an xpath locator is probably your best bet.

However, the 2 dropdowns, as you say, have the same name and id. I think I'd raise this as a bug - ids are generally meant to be unique at the very least. If nothing else, it's made your automated test creation effort that much harder - testability is a measure of how easy the system is to test. Duplicate ids decrease testability!

0

I can find the difference , If you want to use the 2nd drop-down. Use the header tag else everything looks same. So try to create the dynamic x-path something like //*[@text="Variable Product Performance"]//following::Select[1]

Try this maybe this helps...

0

when ever you want to find an element uniquely , and that element doesn't have a unique attribute then find a parent that has an unique attribute and use it as referrence

In your case the div tag is the referrence , if you want second drop down use:

product_id_box = driver.find_element_by_xpath('//div[@class="Site-secondary"]//*[@id="productid"]')

you can also do :

parent = driver.find_element_by_class_name('Site-secondary')
product_id_box=  parent.find_element_by_id("product-id")

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.