I have a HTML code like this:
<ul aria-hidden="false" aria-labelledby="resultsPerPage-button" id="resultsPerPage-menu" role="listbox" tabindex="0" class="ui-menu ui-corner-bottom ui-widget ui-widget-content" aria-activedescendant="ui-id-2" aria-disabled="false" style="width: 71px;">
<li class="ui-menu-item">
<div id="ui-id-1" tabindex="-1" role="option" class="ui-menu-item-wrapper">20</div>
</li>
<li class="ui-menu-item"><div id="ui-id-2" tabindex="-1" role="option" class="ui-menu-item-wrapper ui-state-active">50</div>
</li>
<li class="ui-menu-item"><div id="ui-id-3" tabindex="-1" role="option" class="ui-menu-item-wrapper">100</div>
</li>
<li class="ui-menu-item"><div id="ui-id-4" tabindex="-1" role="option" class="ui-menu-item-wrapper">200</div>
</li>
</ul>
I want to click on "200". Can u help me? I used selenium in python 2.7
I tried doing this:
import time
time.sleep(10)
x=driver.find_element_by_link_text("200").click()
x.click()
time.sleep(8)
The problem here is that the element that contains the text 200
is not a "Link", but only a li
tag which could work as a clickable element was defined on that site.
The documentation doesn't specify it directly, but "Link" means only a
tags.
The idea is the same, but you'll have to find that element on a different way than thinking about as a Link. Using xpath would be I think the best way for this approach:
x = driver.find_element_by_xpath("//div[./text()='200']")
x.click()
Now of course that would work for finding an element depending on the text
it contains, but for finding the specific node you want would be even easier and better to use the id
, as it should always be unique:
x = driver.find_element_by_id('ui-id-4')
I can run it by use of "send_keys":
import time
number.click()
number.send_keys("200")
var200=driver.find_element_by_xpath("""//*[@id="ui-id-4"]""")
var200.click()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With