Selenium and changing elements

My application under test has a very nice feature. When a page loads, 3 listboxes are shown and at least 4 input fields. When the last lisbox is changed, it triggers some code. The remaining input fields are changed to listboxes. Ofcourse these new Listboxes have the same ID as the Input fields.

The first problem I encouterd is what happens exactly. With Selenium I got several error messages that did not give me a clue of what had happened. There was a message that the specified field was an Input instead of a Select. Another was that the element was not available any more.

I tried to solve it by trying to wait for the select element, but that didn’t work because the Input field had the same ID as the Select. The name property was not filled in. Then I added a check if the specified field was of the class Select. At first it did not work, but after seperating them it did. Below is the code:

int a = 0;
while(a == 0) {
if(driver.findElement( By.id(tfTemp.getID()) ).getTagName().equalsIgnoreCase("select")) {
a = 1;
}
}

while(ExpectedConditions.presenceOfElementLocated( By.id(tfTemp.getID()) ) == null ) {
//...
}

For now this works, but if you have a better idea, please do not hesitate to contact me. Also I have only tested this with Internet Explorer 10.

@Edit:
After thinking this over (again), I changed the order. First wait until you find a SELECT, then wait if it is visible.

Advertisements
Selenium and changing elements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s