简体   繁体   English

Selenium - 如何获得以下兄弟姐妹?

[英]Selenium - How to get following sibling?

So I want to target a textbox that appears in a list that comes after the label "First Name" and send a first name to the box, but can't seem to be able to target the textBox...所以我想定位一个出现在标签“名字”之后的列表中的文本框,并将名字发送到该框,但似乎无法定位文本框...

What I've tried:我试过的:

        WebElement firstNameLocTry = driver.findElement(By.xpath("//label[text()='First Name']/following-sibling::div"));
        firstNameLocTry.sendKeys(firstName);

What the li look like:李长什么样子:

<li class="WPTO WKVO" role="presentation" data-automation-id="formLabelRequired">

<div class="WBUO WETO WDUO">
<label id="56$551056--uid24-formLabel" data-automation-id="formLabel" for="56$551056--uid24-input">First Name</label>
<div class="WEUO wd-c8594868-6b31-4526-9dda-7d146648964b" aria-hidden="true">First Name</div>
</div>

<div data-automation-id="decorationWrapper" id="56$551056" class="WFUO">
<div class="WICJ">
<div class="WMP2 textInput WLP2 WJ5" data-automation-id="textInput" id="56$551056--uid24" data-metadata-id="56$551056" style="visibility: visible;">
<input type="text" class="gwt-TextBox WEQ2" data-automation-id="textInputBox" tabindex="0" role="textbox" id="56$551056--uid24-input" aria-invalid="false" aria-required="true">
</div>
</div>
</div>

</li>

Any reason my sendKeys just leads to Element not interactable?我的 sendKeys 只是导致 Element 不可交互的任何原因?

The attached HTML code Produce below out put附加的 HTML 代码 Produce 下面输出

在此处输入图片说明

With the given XPath points to the second "First Name" Div [below pic], when you perform sendKeys , it is obvious that the error " Element not interactable " will be thrown.给定的 XPath 指向第二个“名字”Div [下图],当您执行sendKeys 时,很明显将抛出错误“元素不可交互”。

在此处输入图片说明

Try with below two Xpaths,尝试使用以下两个 Xpath,

1. //label[text()='First Name']//parent::div/following-sibling::div
2. //label[text()='First Name']//parent::div/following-sibling::div//input

Please use following xpath:请使用以下 xpath:

//div[text()='First Name']

or try:或尝试:

//*[contains(text(),'First Name')]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM