英文:
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']
这也不起作用。
英文:
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.
答案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(), '<part of the text above the dropdown>')]]/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(),'Is there an interpreter or someone else speaking on the behalf')]/following-sibling::div[@class='select-container']/div[@class='select2-container']/input
Note - Change the destination element as per your need. Here i have used /input
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论