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

huangapple go评论94阅读模式
英文:

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

问题

我尝试了不同的 XPath。

//*[@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?')]]

这个 XPath 是所有下拉框的常见 XPath,而且 id 是动态的。所以,需要找出另一种方法。

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

这也不起作用。

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

英文:

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.

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

答案1

得分: 1

尝试找到一些适用于所需控件的唯一特征。例如,仅包含标签的 div,或者仅作为某个具有唯一类的 span 的子元素的 div 等。我可以建议以下XPath表达式:

//div[label[contains(text(), '<下拉框上方文本的一部分>')]]/div[@class = 'select_container']
英文:

Try find some unique for needed control. E.g. Only the needed div contains labels, or only the needed div is child of span with some unique class, etc. I can suggest the next XPath:

//div[label[contains(text(), &#39;&lt;part of the text above the dropdown&gt;&#39;)]]/div[@class = ‘select_container’]

答案2

得分: 1

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

英文:

Answer is here

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

答案3

得分: 0

请尝试以下代码 - 这是手写的,如果有任何拼写错误,请更正。

//label[contains(text(),'是否有口译员或其他人代表发言')]/following-sibling::div[@class='select-container']/div[@class='select2-container']/input

注意 - 根据您的需求更改目标元素。这里我使用了 /input

英文:

Try below code - It was hand-written so if there is any spelling error please correct it.

//label[contains(text(),&#39;Is there an interpreter or someone else speaking on the behalf&#39;)]/following-sibling::div[@class=&#39;select-container&#39;]/div[@class=&#39;select2-container&#39;]/input

Note - Change the destination element as per your need. Here i have used /input

huangapple
  • 本文由 发表于 2020年7月28日 12:49:41
  • 转载请务必保留本文链接:https://go.coder-hub.com/63127214.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定