0

I'm relatively new to Webdriver, and I am wondering if it is possible to select items on a dropdown that use a guid.

Normally, I would use

new Select (driver.findElement(By.id("location"))).selectByVisibleText("value");

However, as the page is using a random identifier for each of the dropdowns which change with each load of the page it is making it extremely difficult to automate!

When the DOB as a whole has been completed, it's ID is 'DateOFBirth'

If I could get some help with this, it would be greatly appreciated,

This the element for the "Date" dropdown

<select class="valid" aria-invalid="false"id="a9fbd53c8d354e4b8a5d74c5ad1499d5" name="DateOfBirth.a9fbd53c8d354e4b8a5d74c5ad1499d5" onchange="OnChangeDateOfBirth('a9fbd53c8d354e4b8a5d74c5ad1499d5', '190a3115711d4415aeaf6bf7fc658e2b', '3dbf7448224e4042ac1e477abc345981', 'DateOfBirth');">

It doesn't seem that there are any singulairties at all when the page is refreshed. is there any way I could start it using the default value? which is "Date:"

Update

- I managed to resolve this using xpaths

new Select(driver.findElement(By.xpath("//div[@id='content-holder']/ul/li[3]/ul/li[5]/fieldset/select"))).selectByVisibleText("14");
3
  • Do they have any constant part or are they completely random? Further, do they have a fixed order so you could use selectByIndex? If none of those apply I do not think that you can test it automatically and maybe you should have a talk with a developer about implementing unique identifiers.
    – Daniel
    Jul 19, 2016 at 15:25
  • We use Angular/Material which also generated random unreliable IDs. So we use tags or names and other tricks to find relevant element. Name is usually good enough, but in case you have multiple elements with same name, you can get a list and loop over it investigating other attributes. Jul 19, 2016 at 15:50
  • I'll have a play around with these, if not I'll chat with the devs. Thanks guys!
    – JPrice
    Jul 20, 2016 at 8:14

1 Answer 1

1

You can also use css selectors like these:

select[name*='DateOfBirth']
select[onchange*='DateOfBirth']
#content-holder select[name*='DateOfBirth']
#content-holder select[onchange*='DateOfBirth']

Not the answer you're looking for? Browse other questions tagged or ask your own question.