Help
cancel
Showing results for 
Search instead for 
Did you mean: 
Highlighted
Copilot Lvl 2
Message 1 of 3

Solved: Trying to locate dropdown list on a page, keep failing.

Hi there,

 

I've been trying to lock xpath of a dropdown list on a webpage, for automation purpose by Selenium.

No luck.

The best result I've got is, that Selenium can click at somewhere in that inputbox area and expand the list (showing all three options). And then, it just can't click any option --- can't find element.

Some say that there's no need to use click. And instead I should go Select.

 

Okay then, for using Select, I need to locate the dropdown list first.

I'm using Firefox Mozilla, and I've made a xPath, according to found attributes.

And my code stops at the dropdown list part.

 

Error Message: Select only works on <select> elements, not on <ul>

There's no unique ID or Value assigned to two status - 'Succeeded' and 'Failed'. Take a look at the picture below.

So I'm now stuck in here - Don't know how to teach the program where to go & find elements (using xPath) on this page. You probably have noticed that 'Failed' and 'Succeeded' are sharing same 'class' as well as 'data-v-...' which is indistinguishable (to me, at least).

 

Maybe someone can share some hints?

Thanks for the time.

 

Dum

 

bank_button_url="//div[@class='left-sider ivu-layout-sider']//li[2]"
bank_status_click="//div[4]//div[1]//div[1]//div[1]//div[1]//span[1]"
bank_status_selection="//div[@class='ivu-select ivu-select-visible ivu-select-single ivu-select-default s-86']//div[@class='ivu-select-dropdown']//ul[@class='ivu-select-dropdown-list']"

driver.find_element_by_xpath(bank_button_url).click()    # it works
sleep(2)
driver.find_element_by_xpath(bank_status_click).click()  # it works
sleep(2)

dropdown=Select(driver.find_element_by_xpath(bank_status_selection))            # Does not work
dropdown.select_by_visible_text("succeed")   # Does not work, sure enough

 

Locating  dropdown list.png

 

image.png

 

Solution:

Finally I've done it.

This xpath works - "//div[4]//div[1]//div[1]//div[2]//ul[2]//li[1]"

It seems we cannot always trust...... well, trust "class" and similar attributes since they can appear more than one time while using same values.

Sorry not so good with terms, but, I suppose that "//div[4]//div[1]//div[1]//div[2]//ul[2]//li[1]" is more accurate:

(1) under the 4th div section, go and find the 1st div

(2) then under that '1st div' section found in step (1), go and find... blahblah....

Hopefully I'm right.

 

Just realised this one is called absolute xpath, no wonder it is absolutely accurate and works.

 

Cheers.

 

 

2 Replies
Highlighted
Commander Lvl 2
Message 2 of 3

Re: Trying to locate dropdown list on a page, keep failing.

Hey, check this out: https://teachyourselftestautomation.com/dynamic-dropdown-selenium/ it seems you are able to use the ".click()" function once you have expanded the initial drop-down box. 



*Mark helpful posts with Accept as Solution to help other users locate important info. Don't forget to give Kudos for great content!*
Highlighted
Copilot Lvl 2
Message 3 of 3

Re: Trying to locate dropdown list on a page, keep failing.

Thanks man. Think I've figured out the solution.

Always going somewhere for answers when I believe there's no hope and always find the solution later on. Life.