-1

I want to select a value from the dropdown menu and I am also able to select a value but it will select another value, not which that I have given.

Please see the below video. when I click on the dropdown one class appears in the background. and using that class I have created XPath but it will select a different value.

https://www.loom.com/share/e60dd141c3da426080646ec527cc029f

I have used this XPath for clicking on the dropdown and selecting values from it.

self.driver.find_element_by_xpath('//*[@id="shipping_address"]//*[@class="Select-arrow"]').click()
time.sleep(2)
self.driver.find_element_by_xpath('//*[@class="Select-menu-outer"]//*[text()="Alaska"]').click()

I have many tried but not successes can anyone can help me?

14
  • Looks like the locator you are using is not unique. Can you share a link to that web page? Commented Dec 9, 2021 at 11:11
  • @Prophet this private so I can not share the link. but I am dam sure the locators are 100% unique. Commented Dec 9, 2021 at 11:18
  • Can you please check that the locators are unique? Commented Dec 9, 2021 at 11:23
  • @Prophet Please see the screenshots ibb.co/r5tzWmq Commented Dec 9, 2021 at 11:26
  • 1
    @TacoVerhagen Please check the screenshots if you got any idea. ibb.co/2FWshd2 Commented Dec 10, 2021 at 5:11

1 Answer 1

-1

The problem: you are clicking the div which contains ALL states instead of the specific state you want. To be exact you click the div[@class="Select-menu"]. What you want is this (1 layer deeper):

self.driver.find_element_by_xpath('//*[@id="shipping_address"]//*[@class="Select-arrow"]').click()
time.sleep(2)
self.driver.find_element_by_xpath('//div[@class="Select-menu-outer"]//div[@role="option" and text()="Alaska"]').click()

General hint, if the FIRST item is always selected than you are clicking 1 level to 'low' in the tree.

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you for your suggestion. But it is not working.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.