2

I have a drop down built with extJS.

<input id="combo-1786-inputEl" data-ref="inputEl" type="text" size="1" name="Query Category" placeholder="Select query category" role="combobox" aria-hidden="false" aria-disabled="false" aria-readonly="false" aria-invalid="true" aria-required="true" aria-haspopup="true" aria-expanded="false" aria-autocomplete="list" class="x-form-field x-form-required-field x-form-text x-form-text-default  x-form-invalid-field x-form-invalid-field-default x-form-empty-field x-form-empty-field-default" autocomplete="off" data-componentid="combo-1786" data-errorqtip="<ul class=&quot;x-list-plain&quot;><li>This field is required</li></ul>" aria-describedby="combo-1786-ariaErrorEl">

As we can see the tag used is 'input' and not 'select'.

So when I looked up about how to populate it, most answers were made under the assumption that it was created using a 'select' tag and it did not work.

Also the drop downitems are fetched from DB only when I click on the arrow on the dropdown: Notice the arrow button on only if we click, the drop down items are retrieved

So as a result of this, the drop down items cant be found on the page source.

Can someone one please suggest how to populate such downs using the best practice?

P.S-I do have a workaround, but its not at all good code practice and not at all generic:

driver.findElement(By.xpath("//*[@id='combo-1731-trigger-picker']")).click();//clicking on the arrow key of the drop down.
//Once the drop down item comes, I am trying to replicate pressing the keyboard arrow key,by sending down arrow key to the drop down item(web element)
//This works for me because I know the extact position of my drop down item in the drop down item list.It will stop working if the postion of the drop item changes
//so below loop just presses the down arrow key required number of times.
for(int i=0;i<5;i++){
    driver.findElement(By.xpath("//*[@id='combo-1731-inputEl']")).sendKeys(Keys.ARROW_DOWN);
}
driver.findElement(By.xpath("//*[@id='combo-1731-inputEl']")).sendKeys(Keys.ENTER);

If you read the comments mentioned along with the above code, then you can understand how fragile the logic is. Please help.

1 Answer 1

1

You are trying to click/ select the item in the drop down correct? Do the drop down items have unique id's? If so you should be able to just pass it the specific xpath id.

I personally use Css to find elements, in that case it would be

driver.find_element(By.CSS_SELECTOR,'#combo-1731-trigger-picker').click()

driver.find_element(By.CSS_SELECTOR, '#combo-1731-inputEl > nth:child(x)').click()

where x = the count of your drop down item.

or if they have unique id's then use

driver.find_element(By.CSS_SELECTOR, '#theUniqueIdGoesHere').click()

I wrote a whole weeks worth of tests, using xpath selectors, it was painful day to day running the test and watching it fail. Going back and changing everything to Css selectors has saved me many head aches since I started writing Auto tests.

Edit: you could try the following,

driver.findElement(By.linkText("Your Links Text Here")).click();

This will only work if each links text is unique as well, if not it will select the first one it finds.

If these work for you would you mind accepting my answer?

Sign up to request clarification or add additional context in comments.

1 Comment

Hey,thanks for the help, the second approach worked actually(where drop down items have unique ids). Basically I tried to find the drop down element in page source and then copied its xpath. Then tried to click on it. But the xpath I got from Chrome tools for that drop down list item is : //*[@id='combo-1731-picker-listEl']/div[17] where 17 is the count of my item in drop down list. This may not work if the count changes. Isn't there any way to get the xpath using the text of my drop down list item.

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.