我需要点击生成的动态复选框,即“ Rec136”
我拥有的是名称=“ 345551”和值=“ 345551”
driver.findElement(By.xpath(".//*[contains(text(),'345551')]")).getText()
我尝试单击复选框:-
executor.executeScript("arguments[0].click();",driver.findElement(By.xpath(".//*[contains(text(),'345551')]")));
HTML:-
<tr id="Rec136">
<td align="center" width="10%">
<input name="345551" value="345551-1" type="checkbox"/>
</td>
<td align="center" width="10%">bnnsnjad</td>
检查复选框后,找到的路径为:
.//*[@id='Rec136']/td[1]/input (Need to click)
使用“ contains”获取元素后如何单击复选框(.//*[@id='Rec136']/td[1]/input)。简而言之,如何在获得值“ 345551”后单击上面的复选框?
答案 0 :(得分:1)
您可以尝试使用此 xpath :
//tr[contains(@id,'Rec136')]/descendant::input
但是ID是动态生成的。因此,使用这些ID并不是一个好习惯。
在代码中:
driver.findElement(By.xpath("//tr[contains(@id,'Rec136')]/descendant::input")).click();
如果要单击具有相应名称的复选框,则xpath将为:
//td[contains(text(),'bnnsnjad')]/preceding-sibling::td/input
代码:
driver.findElement(By.xpath("//td[contains(text(),'bnnsnjad')]/preceding-sibling::td/input ")).click();
答案 1 :(得分:0)
如果id是动态的,并且您具有名称/值,则可以尝试:
protected virtual void SOLine_RowUpdating(PXCache cache, PXRowUpdatingEventArgs e)
{
if (e.NewRow == null)
{
return;
}
SOLine soLine = (SOLine)e.NewRow;
SOLine relatedLine = Base.Transactions.Search<SOLine.inventoryID>(456);
if (relatedLine != null)
{
SOLine oldRelatedLine = PXCache<SOLine>.CreateCopy(relatedLine);
relatedLine.Qty = soLine.Qty;
relatedLine.CuryUnitPrice = 24.20;
object outPrice = 0.01;
outPrice = (relatedLine.CuryUnitPrice * relatedLine.Qty);
cache.SetValueExt<SOLine.curyExtPrice>(relatedLine, outPrice);
Base.Transactions.Cache.RaiseRowUpdated(relatedLine, oldRelatedLine);
Base.Transactions.Update(relatedLine);
Base.Transactions.View.RequestRefresh();
}
}
OR
driver.findElement(By.xpath("//input[name()='345551']")).click();