1

I am writing an automation for work and am stuck with a dropdown. The particular select box in question is as follows:

<span class="a-dropdown-container" id="select-size-bulk-asin">
    <select name="display_type" class="a-native-dropdown">
        <option value="SMALL-IMAGES">SMALL-IMAGES</option>
        <option value="LARGE-IMAGES">LARGE-IMAGES</option>
        <option value="TEXT">TEXT</option>
    </select>

    <span tabindex="-1" data-a-class="a-spacing-small" class="a-button a-button-dropdown a-spacing-small">
        <span class="a-button-inner">
        <span class="a-button-text a-declarative" data-action="a-dropdown-button" aria-haspopup="true" role="button" tabindex="0" aria-pressed="false" aria-owns="2_dropdown_combobox">
        <span class="a-dropdown-prompt">SMALL-IMAGES</span>
        </span>
        <i class="a-icon a-icon-dropdown"></i>
        </span>
        </span>
    </span>

It defaults to 'SMALL Images' and I would like to select the 'TEXT' option. I am receiving element not clickable error. The page is simple and the element is visible on the screen.

The list of methods I did try are:

  • Used WebDriverWait to wait for the element to be visible;
  • Used WebDriverWait to wait for the element to be clickable;
  • Used the select class to set the selected option;
  • I also read through a question.

I am thinking if I should just go to the next element and send Shift+Tabs until I reach this drop down and then down arrow keys. But would like to use that only as the last resort.

NOTE: - I am using Python 3 and Chrome.

1
  • 1
    Post your code and error message. Commented Jun 24, 2018 at 8:17

1 Answer 1

0

You can try this code to select value from drop down :

select = Select(driver.find_element_by_id('select-size-bulk-asin'))
select.select_by_visible_text('TEXT')  

However,as you have mentioned you are receiving element not clickable exception. you can try this code :

WebDriverWait(browser, 30).until(EC.element_to_be_clickable((By.ID, "select-size-bulk-asin")))

As a last resort you can go ahead with :

drop_down= driver.find_element_by_id("select-size-bulk-asin")
drop_down.click()

actions = ActionChains(driver)
actions.send_keys(Keys.ARROW_DOWN)
actions.send_keys(Keys.ARROW_DOWN)
actions.send_keys(Keys.ENTER)
actions.perform()
Sign up to request clarification or add additional context in comments.

2 Comments

I was finally able to use the ActionChains library as per this suggestion and it worked. Thank you!!!
@VigneshPalani : Glad it worked for you. Happy sunday.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.