Search code examples
javaseleniumselenium-webdriverxpathdropdown

How do I find an element that contains a dynamic id and repetitive classname?


I have tried different x-paths.

//*[@id='c635_container']
//div[@id='c635_container']
(//div[@class = 'select_container'])[16]

Tried these as well but it selects two paths.

//div[label[contains(text(),'Is there an interpreter or someone else speaking on the behalf of the customer?')]]//div[@class='select-container']




//div[(label[contains(text(),'Is there an interpreter or someone else speaking on the behalf of the customer?')])[1]]

//div[label[contains(text(),'Is there an interpreter or someone else speaking on the behalf of the customer?')] and //input[@class='select2-focusser select2-offscreen']][1]

//div[@class='select-container'] and //label[contains(text(),'Is there an interpreter or someone else speaking on the behalf of the customer?')] and //input[@class='select2-focusser select2-offscreen']]

//div[label[contains(text(),'Is there an interpreter or someone else speaking on the behalf of the customer?')]]

This

//div[@class = ‘select_container’]

is common XPath for all dropdowns and ids are dynamic. So, Need to figure it out another way.

Please check the link:-

https://drive.google.com/file/d/1a96K2Zo7wOTZIHdBXLo_z-2WSO3T0b2R/view?usp=sharing

//div//label[text()='Is there an interpreter or someone else speaking on the behalf of the customer?'] and //div[@class='select-container']

This also does not work.

enter image description here


Solution

  • Answer is here

    //h1[text()=‘Interpreter’]/following-sibling::div//a[@class=‘select2-choice’]