2

I have a HTML page containing a form with an tag. I want to set the value of the drop down in this tag using Selenium.

This is how I retrieve the input element:

driver.find_element_by_xpath("/html/body/div[2]/div/div/form/div/div[1]/div[3]/div[1]/div/div[1]/input")

I tried to set the value using select_month.send_keys("09") but this is not accepted by the web page when I try to submit the form so I need to find another method.

EDIT: Here is the HTML of the form, I have ensured that it is the right element in my x-path:

<input autocomplete="off" tabindex="-1" class="ui-select-search ui-select-toggle ng-pristine ng-valid ng-touched" ng-click="$select.toggle($event)" placeholder="Select month" ng-model="$select.search" ng-hide="!$select.searchEnabled || ($select.selected &amp;&amp; !$select.open)" ng-disabled="$select.disabled" type="text">
5
  • is there any other input elements at same level? can you try with firebug to ensure element location is correct. Commented Sep 30, 2015 at 13:49
  • I have ensured that the Xpath is correct. Commented Sep 30, 2015 at 14:08
  • 1
    How about driver.find_element_by_xpath("//input[@placeholder='Select month']")? Commented Sep 30, 2015 at 14:09
  • Ok, that works as well for locating the element, but does not solve my dropdown problem. Commented Sep 30, 2015 at 14:16
  • 1
    dropdown? where is it? Commented Sep 30, 2015 at 14:29

1 Answer 1

1

After messing around a bit and incorporating the better practice presented by alecxe, this solution worked...

driver.find_element_by_xpath("//input[@placeholder='Select month']").click()
driver.find_element_by_xpath("//*[contains(text(), '09')]").click()
Sign up to request clarification or add additional context in comments.

Comments

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.