gpt4 book ai didi

Xpath - how to exclude element's child?(XPath-如何排除元素的子元素?)

转载 作者:bug小助手 更新时间:2023-10-25 17:59:45 25 4
gpt4 key购买 nike



I have the following html code:

我有以下html代码:


<div class="form-field checkbox-terms_of_services">
<input id="register-terms_of_services" type="checkbox" class="input-block checkbox">
<label for="register-terms_of_services">
</label
</div>

enter image description here


I'm trying to click on the checkbox.

我正在尝试点击该复选框。


I tried this xpath:
//input[@class='input-block checkbox']

我尝试了XPath://INPUT[@CLASS=‘输入块复选框’]


but it's ignore it.

但它忽略了它。


so I took the div above, but it's clicking on the link of terms of services.
How can I build an XPATH that will take the div element and exclude the label element?

所以我选择了上面的div,但它点击的是服务条款的链接。如何构建一个接受div元素并排除Label元素的XPath?


更多回答

I don't understand; XPath can't "click" so what are you talking about?

我不明白;XPath不能“点击”,那你在说什么呢?

better use the id attribute than the class one //input[@id="register-terms_of_services"]

最好使用id属性而不是类one//输入[@id=“Register-Terms_of_Services”]

@Fravadona the element of this xpath do nothing if I code element.click(); @LMC the website recognize the xpath, but while running the click doesn't happened. if I use the div above, it's clicking on the link of terms of service. I try to find a way to ignore this link and click on the checkbox. if there is such a way.

@Fravadona如果我编写元素代码,则此XPath的元素不会执行任何操作。ick();@lmc网站可以识别该XPath,但在运行时不会发生单击。如果我使用上面的div,它会点击服务条款的链接。我试图找到一种忽略此链接的方法,并点击该复选框。如果有这样的方法的话。

@chanak you can add the checked attribute to the input checkbox element

@Chanak您可以将选中的属性添加到输入复选框元素

waht do you mean with link of terms of services.?

你说的服务条款链接是什么意思?

优秀答案推荐

I found a working solution:

我找到了一个可行的解决方案:


if(!element.isSelected()) {
element.sendKeys(Keys.SPACE);
}

In this way the checkbox is correctly selected

通过这种方式,复选框被正确选中


更多回答

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com