2

I'm using Excel VBA, Selenium and Chrome.

Threse is a dropdownbox box and I'm trying to select an option. Html code is:

<div class="x-form-field-wrap x-form-field-trigger-wrap x-abs-layout-item x-trigger-wrap-focus" id="ext-gen437" style="width: 100px; left: 330px; top: 70px;">

<input maxlength="1" spellcheck="false" id="ext-comp-1233" name="CITTADINANZA"        class="x-form-text x-form-field x-field-uppercase x-trigger-noedit x-form-focus" readonly="" style="width: 75px;" />

<img src="data:image/gif;base64,R0lGODlhAQABAID/AMDAwAAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==" alt="" class="x-form-trigger x-form-arrow-trigger" id="ext-gen438" />

</div>

The dispalyed text options are "Si" and "No" but in Html code there are no options, index, value...(it's just an input element; the img element is the arrow you have to click for a dropdown)

I tried to fill the input element using:

driver.FindElementByCss("#ext-comp-1233").AsSelect.SelectByIndex
driver.FindElementByCss("#ext-comp-1233").AsSelect.SelectByValue
driver.FindElementByCss("#ext-comp-1233").AsSelect.SelectByText
driver.FindElementByCss("#ext-comp-1233").Sendkeys

but I recive the error: "Unexpected TagName Error. Expected=select Got=input"

...while Sendkeys doesn't work.

Do you have any idea?

Thanks :)

10
  • It seems that the dropdown element is dynamic. So it may not be a select element. You can try clicking on the down arrow image, wait for a second, and click on the drop down entry. You may first inspect the drop down after clicking on the image to see the real html code Commented Oct 2, 2015 at 11:32
  • @ShalvinAbraham Thank you for answer. After clicking on the image the input html code doesn't change, only change a bit the class code of div. I can click on the down arrow image and sendkey a downarrow but when I sendkey enter (for choose the option) is not working. Commented Oct 2, 2015 at 12:24
  • Did you try to inspect the option element ? I think it will be another div. Commented Oct 2, 2015 at 13:06
  • @ShalvinAbraham What/where is the option element? I can't find other hmtl elements than I posted ( Commented Oct 2, 2015 at 15:22
  • These dynamic elements work in such a way that, JavaScript is used to dynamically create elements. What you can try is, click on the dropdown (down arrow image) and once you see the options, right click on one of them and choose inspect element. Then, you will see more elements inside the input element, or other element. Can you check this out? Commented Oct 2, 2015 at 16:58

2 Answers 2

5

Try this:

obj.FindElementByXPath("xpath of element").AsSelect.SelectByText ("option text")

Note: driver - name of the object you've created for webdriver.

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

1 Comment

This was enough to help me figure out what I needed, thanks!
0

The solution is to click on the drop down image, and when the dynamically created divs are displayed, click on those divs.

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.