I've been trying to lock xpath of a dropdown list on a webpage, for automation purpose by Selenium.
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.
bank_button_url="//div[@class='left-sider ivu-layout-sider']//li" bank_status_click="//div//div//div//div//div//span" 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
Finally I've done it.
This xpath works - "//div//div//div//div//ul//li"
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//div//div//div//ul//li" 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.
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.
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.