gpt4 book ai didi

java - 无法通过 selenium webdriver 中的 XPath 选择特定列的文本框

转载 作者:行者123 更新时间:2023-12-01 11:29:15 25 4
gpt4 key购买 nike

我的Java

package com.ej.zob.modules;

import java.util.List;

import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;

public class Revenue_Month {
public void Execute()
{
LaunchApplication.driver.findElement(By.linkText("VIEW")).click();
LaunchApplication.driver.findElement(By.linkText("REVENUE")).click();
LaunchApplication.driver.findElement(By.name("click")).click();
List<WebElement> c = LaunchApplication.driver.findElements(By.xpath("//a[contains(@id,'Edit_')]"));
for(WebElement elem_1:c)
{
elem_1.click();
}
List<WebElement> w = LaunchApplication.driver.findElements(By.xpath("//td[position() = count(ancestor::table/tbody/tr/td[.='May']/preceding-sibling::*)+1]"));
//for(WebElement elem:w)
//{
// elem.
// elem.sendKeys("50");
// elem.click();
//}

}
}

我的 HTML

<div id="idshowtable" style="background:#7F4F20">
<table id="mainTable" border="1">
<tbody>
<tr>
<td align="center" colspan="14">State Wise Revenue of a Bank (all Figures are in INR and in Lacs)</td>
</tr>
<tr>
<td>State \ Month</td>
<td>
<a href="#" onclick="">October</a>
</td>
<td>
<a href="#" onclick="">November</a>
</td>
<td>
<a href="#" onclick="">December</a>
</td>
<td>
<a href="#" onclick="">January</a>
</td>
<td>
<a href="#" onclick="">February</a>
</td>
<td>
<a href="#" onclick="">March</a>
</td>
<td>
<a href="#" onclick="">April</a>
</td>
<td>
<a href="#" onclick="">May</a>
</td>
<td>
<a href="#" onclick="">June</a>
</td>
<td>
<a href="#" onclick="">July</a>
</td>
<td>
<a href="#" onclick="">August</a>
</td>
<td>
<a href="#" onclick="">September</a>
</td>
<td>
<a href="#" onclick="">Operation</a>
</td>
</tr>
<tr>
<td>Rajasthan</td>
<td>
<div>
<input id="1_1" type="text" value="51838" style="width:50px" name="U1">
<br>
<input type="button" value="Update" onclick="fnUpdateRevenue("1_1")" style="width:60px">
</div>
</td>
<td>
<div>
<input id="1_2" type="text" value="62192" style="width:50px" name="U1">
<br>
<input type="button" value="Update" onclick="fnUpdateRevenue("1_2")" style="width:60px">
</div>
</td>
<td>
<div>
<input id="1_3" type="text" value="87617" style="width:50px" name="U1">
<br>
<input type="button" value="Update" onclick="fnUpdateRevenue("1_3")" style="width:60px">
</div>
</td>
<td>
<div>
<input id="1_4" type="text" value="59826" style="width:50px" name="U1">
<br>
<input type="button" value="Update" onclick="fnUpdateRevenue("1_4")" style="width:60px">
</div>
</td>
<td>
<div>
<input id="1_5" type="text" value="97075" style="width:50px" name="U1">
<br>
<input type="button" value="Update" onclick="fnUpdateRevenue("1_5")" style="width:60px">
</div>
</td>
<td>
<div>
<input id="1_6" type="text" value="58818" style="width:50px" name="U1">
<br>
<input type="button" value="Update" onclick="fnUpdateRevenue("1_6")" style="width:60px">
</div>
</td>
<td>
<div>
<input id="1_7" type="text" value="41250" style="width:50px" name="U1">
<br>
<input type="button" value="Update" onclick="fnUpdateRevenue("1_7")" style="width:60px">
</div>
</td>
<td>
<div>
<input id="1_8" type="text" value="52233" style="width:50px" name="U1">
<br>
<input type="button" value="Update" onclick="fnUpdateRevenue("1_8")" style="width:60px">
</div>
</td>
<td>
<div>
<input id="1_9" type="text" value="74272" style="width:50px" name="U1">
<br>
<input type="button" value="Update" onclick="fnUpdateRevenue("1_9")" style="width:60px">
</div>
</td>
<td>
<div>
<input id="1_10" type="text" value="28197" style="width:50px" name="U1">
<br>
<input type="button" value="Update" onclick="fnUpdateRevenue("1_10")" style="width:60px">
</div>
</td>
<td>
<div>
<input id="1_11" type="text" value="79977" style="width:50px" name="U1">
<br>
<input type="button" value="Update" onclick="fnUpdateRevenue("1_11")" style="width:60px">
</div>
</td>
<td>
<div>
<input id="1_12" type="text" value="11158" style="width:50px" name="U1">
<br>
<input type="button" value="Update" onclick="fnUpdateRevenue("1_12")" style="width:60px">
</div>
</td>
<td>
<a id="Edit_1" href="#" onclick="fnEditRevenue("1");" style="visibility: hidden;">Edit</a>
|
<a id="Hide_1" href="#" onclick="fnHideRevenue(1);" style="visibility: hidden;">Hide</a>
|
<a id="Show_1" href="#" style="visibility:hidden" onclick="fnShowRevenue(1);">Show</a>
</td>
</tr>
<tr>
<td>Sikkim</td>
<td>
<div>
<input id="2_1" type="text" value="66503" style="width:50px" name="U2">
<br>
<input type="button" value="Update" onclick="fnUpdateRevenue("2_1")" style="width:60px">
</div>
</td>
<td>
<div>
<input id="2_2" type="text" value="84033" style="width:50px" name="U2">
<br>
<input type="button" value="Update" onclick="fnUpdateRevenue("2_2")" style="width:60px">
</div>
</td>
<td>
<div>
<input id="2_3" type="text" value="37062" style="width:50px" name="U2">
<br>
<input type="button" value="Update" onclick="fnUpdateRevenue("2_3")" style="width:60px">
</div>
</td>
<td>
<div>
<input id="2_4" type="text" value="25780" style="width:50px" name="U2">
<br>
<input type="button" value="Update" onclick="fnUpdateRevenue("2_4")" style="width:60px">
</div>
</td>
<td>
<div>
<input id="2_5" type="text" value="70574" style="width:50px" name="U2">
<br>
<input type="button" value="Update" onclick="fnUpdateRevenue("2_5")" style="width:60px">
</div>
</td>
<td>
<div>
<input id="2_6" type="text" value="99017" style="width:50px" name="U2">
<br>
<input type="button" value="Update" onclick="fnUpdateRevenue("2_6")" style="width:60px">
</div>
</td>
<td>
<div>
<input id="2_7" type="text" value="1406" style="width:50px" name="U2">
<br>
<input type="button" value="Update" onclick="fnUpdateRevenue("2_7")" style="width:60px">
</div>
</td>
<td>
<div>
<input id="2_8" type="text" value="42724" style="width:50px" name="U2">
<br>
<input type="button" value="Update" onclick="fnUpdateRevenue("2_8")" style="width:60px">
</div>
</td>
<td>
<div>
<input id="2_9" type="text" value="22180" style="width:50px" name="U2">
<br>
<input type="button" value="Update" onclick="fnUpdateRevenue("2_9")" style="width:60px">
</div>
</td>
<td>
<div>
<input id="2_10" type="text" value="27663" style="width:50px" name="U2">
<br>
<input type="button" value="Update" onclick="fnUpdateRevenue("2_10")" style="width:60px">
</div>
</td>
<td>
<div>
<input id="2_11" type="text" value="88324" style="width:50px" name="U2">
<br>
<input type="button" value="Update" onclick="fnUpdateRevenue("2_11")" style="width:60px">
</div>
</td>
<td>
<div>
<input id="2_12" type="text" value="42853" style="width:50px" name="U2">
<br>
<input type="button" value="Update" onclick="fnUpdateRevenue("2_12")" style="width:60px">
</div>
</td>
<td>
<a id="Edit_2" href="#" onclick="fnEditRevenue("2");" style="visibility: hidden;">Edit</a>
|
<a id="Hide_2" href="#" onclick="fnHideRevenue(2);" style="visibility: hidden;">Hide</a>
|
<a id="Show_2" href="#" style="visibility:hidden" onclick="fnShowRevenue(2);">Show</a>
</td>
</tr>

我无法选择特定月份的列中的文本框。

//td[position() = count(ancestor::table/tbody/tr/td[.='May']/preceding-sibling::*)+1]

通过此 XPath,我可以选择月份名称“may”和所有 tr。但我想使用月份名称仅选择预期列的列和特定输入文本框。

最佳答案

我猜你的问题不太清楚。但是,我假设要求是使用月份名称查找列和关联的 td 。如果是这样,请尝试以下操作:

//td[count(//td//a[contains(.,'October')]//.)]

编辑

因为,您只需要使用 type='text'inputs 添加额外的过滤;

//td[count(//td//a[contains(.,'October')]//.)]//input[@type='text']

关于java - 无法通过 selenium webdriver 中的 XPath 选择特定列的文本框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30555470/

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