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

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

我尝试了不同的 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 是动态的。所以,需要另辟蹊径。

请检查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']

这也不行。

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

//div[label[contains(text(), '<part of the text above the dropdown>')]]/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’]