Java 如何找到包含动态id和重复类名的元素?

Java 如何找到包含动态id和重复类名的元素?,java,selenium,selenium-webdriver,xpath,dropdown,Java,Selenium,Selenium Webdriver,Xpath,Dropdown,我尝试过不同的x路径 //*[@id='c635_container'] //div[@id='c635_container'] (//div[@class = 'select_container'])[16] 也尝试了这些方法,但它选择了两条路径 //div[label[contains(text(),'Is there an interpreter or someone else speaking on the behalf of the customer?')]]//div[@class

我尝试过不同的x路径

//*[@id='c635_container']
//div[@id='c635_container']
(//div[@class = 'select_container'])[16]
也尝试了这些方法,但它选择了两条路径

//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?')]]
这个

//div[@class='select_container']

是所有下拉列表的公共XPath,ID是动态的。所以,我们需要用另一种方法来解决这个问题

请查看以下链接:-

这也不起作用


尝试找到一些独特的控制方法。例如,只有所需的div包含标签,或者只有所需的div是具有某个唯一类的span的子级,等等。我可以建议下一个XPath:

//div[label[contains(text(), '<part of the text above the dropdown>')]]/div[@class = ‘select_container’]
//div[label[contains(text(),'')]/div[@class='select_container']

尝试下面的代码-它是手写的,因此如果有任何拼写错误,请更正它

//label[contains(text(),'Is there an interpreter or someone else speaking on the behalf')]/following-sibling::div[@class='select-container']/div[@class='select2-container']/input
注意-根据需要更改目标元素。这里我用了
/input

答案在这里

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

-尝试了此操作,但它选择了两个元素//div[label[contains(text(),“是否有口译员或其他人代表客户发言?”)和//div[@class'select-container']]Remove,并且,它应该指向正确的元素://div[label[contains(text(),“是否有口译员或其他人代表客户发言?”)]//div[@class='select-container']试试这个://div[label[contains(text(),“是否有口译员或其他人代表客户说话?”)]//div[@class='select-container']我试过了,但没用。您已经在上面提到了。请检查我是否更新了问题,我在哪里也提到了我尝试过的所有路径?我们有URL吗?对不起!我无法将URL作为其高度安全的站点共享。它没有选择我要选择的下拉列表。直到//label[contains(text(),“是否有解释器或其他人代表发言”)]正常,但在此之后,它不会选择任何下拉引用-
//h1[text()=‘Interpreter’]/following-sibling::div//a[@class=‘select2-choice’]