How can I click on numeric buttons (onclick Event) using selenium in python?

I have an 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 press "200". Could you help me? I used selenium in python 2.7

I tried to do this:

 import time time.sleep(10) x=driver.find_element_by_link_text("200").click() x.click() time.sleep(8) 
+4
source share
2 answers

I can run it using send_keys:

 import time number.click() number.send_keys("200") var200=driver.find_element_by_xpath("""//*[@id="ui-id-4"]""") var200.click() 
+1
source

The problem is that the element containing the text 200 is not a "link", but only the li tag was defined on this site, which could work as an interactive element.

the documentation does not indicate it directly, but β€œLink” means only a tags .

The idea is the same, but you will have to find this element differently than thinking about Link. Using xpath would be best for this approach:

 x = driver.find_element_by_xpath("//div[./text()='200']") x.click() 

Now, of course, this will help to find the element depending on the text contained in it, but to find a specific node it will be easier and easier for you to use id , since it should always be unique:

 x = driver.find_element_by_id('ui-id-4') 
+6
source

Source: https://habr.com/ru/post/1274334/


All Articles