gpt4 book ai didi

java - xpath 元素识别 -- Cleaner Xpath

转载 作者:行者123 更新时间:2023-11-28 02:52:29 25 4
gpt4 key购买 nike

我能够使用直接从代码复制的实际 xpath 来识别元素,但是有人可以使用以下代码帮助我编写更简单的 xpath 吗?以下代码是工作代码!

WebElement oCheckbox = myDriver.findElement(By.xpath(".//*[@id='app']/div[1]/div[2]/div/div/div[2]/div/div[1]/div/div/div[2]/div[2]/table/tbody/tr[1]/td[1]/div/label/div/i"));
WebElement oCheckbox1 = myDriver.findElement(By.xpath(".//*[@id='app']/div[1]/div[2]/div/div/div[2]/div/div[1]/div/div/div[2]/div[2]/table/tbody/tr[2]/td[1]/div/label/div/i"));
oCheckbox.click();
oCheckbox1.click();

HTML:

<head>
<body class="">
<div id="app">
<section class="bottom-padding cf top-padding white-bg">
<div class="container">
<div class="row">
<div class="row">
<div class="col">
<div class="row">
<div class="col-lg-3 push-lg-9 padding-l-r-30 padding-bottom">
<div class="col-lg-9 pull-lg-3 padding-l-r-15">
<div class="row dropshadow">
<div class="col-lg-5 padding-none">
<div class="left-round fixed-height gray-bg">
<div>
<div class="section-title">
<div class="floatThead-wrapper" style="position: relative; clear: both;">
<div class="floatThead-container" style="overflow: hidden; padding-left: 0px; padding-right: 0px; position: absolute; margin-top: 0px; top: 0px; z-index: 1001; will-change: transform; transform: translateX(0px) translateY(0px); left: 0px; width: 410.867px;" aria-hidden="true">
<div class="table-wrapper">
<table class="table protocol-table" style="table-layout: fixed; min-width: 410.867px;">
<colgroup>
<thead>
<tbody>
<tr>
<td>
<div>
<input id="select-pcsl-9777-protocol" type="checkbox"/>
<label for="select-pcsl-9777-protocol">
<div>
<i class="fa fa-check" aria-hidden="true"/>
</div>
<span class="sr-only">Select</span>
</label>

最佳答案

试试这个:

myDriver.findElement.ById("select-pcsl-9777-protocol")

关于java - xpath 元素识别 -- Cleaner Xpath,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46609419/

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