Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

unable to navigate down in a drop down list , using keys.ARROW_DOWN in Selenium webdriver using Python

I was facing issues while getting the text from my elements and getting some issues while trying to get value of hidden elements, so I tried to use key down to make hidden elements visible and then get the text from it.

I have been trying to navigate to the rows of a table using the arrow_down key but its not working even after trying multiple options.

my html file structure is like:

<table class="activities-table">
<thead style="display:none">
<tbody>
<tr>
<tr>
<tr>
<tr>
<tr>
<tr>
<tr>
<tr>

I have elements corresponding to each .

Things that I tried so far:

1.
    elem_list = self.elements
    elem = elem_list[0] #took the first element
    actions = ActionChains(driver)
    actions.click(elem).send_keys_to_element(elem,Keys.SPACE ).perform()
2.
    elem_pos = elem.location['y']
    driver.execute_script("window.scroll(0, %s)"%elem_pos)
    elem.click()
    time.sleep(2)
    elem.send_keys(Keys.ARROW_DOWN)
3.
    elem_list = self.elements
    elem = elem_list[0]
    elem.click()
    elem.send_keys(Keys.ARROW_DOWN)

Every time the click works but send_keys is executed without performing any action.

like image 726
djey Avatar asked Dec 06 '25 20:12

djey


1 Answers

Solved above problem with following.

elem1 below is the element of the table scroller:

elem1 = driver.find_element_by_xpath(<xpath of the table scroller>)
actionChains = ActionChains(driver);
numberOfPixels = 50;
actionChains.move_to_element(elem1).click_and_hold().move_by_offset(0,numberOfPixels).release().perform();

The number of pixels to be drag can be varied as per requirement

like image 195
user3640664 Avatar answered Dec 08 '25 10:12

user3640664



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!