我的代码如下。在这里,我需要点击带有文字'生产计划'的元素。在菜单列表中。代码不起作用,请提供一些建议。
List<WebElement> list = driver.findElements(By.xpath("html/body/div[4]"));
for(WebElement we : list) {
if(we.getText().contains("Production Plan")) {
we.click();
}
html代码是,
<div style="position: absolute; visibility: visible; background-color: rgb(255, 255, 255); width: 142px; height: 236px; font-family: Verdana,Arial,Helvetica,sans-serif; font-weight: normal; font-style: normal; font-size: 8pt; z-index: 102; top: 84px; left: 0px;">
<div style="position: absolute; visibility: inherit; overflow: hidden; cursor: default; color: rgb(255, 255, 255); background-color: rgb(25, 63, 148); text-align: left; width: 140px; height: 16px; padding-left: 0px; padding-top: 2px; left: 1px; top: 1px;">Material Group</div>
<div style="position: absolute; visibility: inherit; overflow: hidden; cursor: default; color: rgb(255, 255, 255); background-color: rgb(25, 63, 148); text-align: left; width: 140px; height: 16px; padding-left: 0px; padding-top: 2px; left: 1px; top: 19px;">Material Sub Group</div>
<div style="position: absolute; visibility: inherit; overflow: hidden; cursor: default; color: rgb(255, 255, 255); background-color: rgb(25, 63, 148); text-align: left; width: 140px; height: 16px; padding-left: 0px; padding-top: 2px; left: 1px; top: 37px;">Material</div>
<div style="position: absolute; visibility: inherit; overflow: hidden; cursor: default; color: rgb(255, 255, 255); background-color: rgb(25, 63, 148); text-align: left; width: 140px; height: 16px; padding-left: 0px; padding-top: 2px; left: 1px; top: 55px;">UoM</div>
<div style="position: absolute; visibility: inherit; overflow: hidden; cursor: default; color: rgb(255, 255, 255); background-color: rgb(25, 63, 148); text-align: left; width: 140px; height: 18px; left: 1px; top: 73px;">
<div style="position: absolute; visibility: inherit; overflow: hidden; cursor: default; color: rgb(255, 255, 255); background-color: rgb(25, 63, 148); text-align: left; width: 140px; height: 16px; padding-left: 0px; padding-top: 2px; left: 1px; top: 91px;">Supplier Type</div>
<div style="position: absolute; visibility: inherit; overflow: hidden; cursor: default; color: rgb(255, 255, 255); background-color: rgb(25, 63, 148); text-align: left; width: 140px; height: 16px; padding-left: 0px; padding-top: 2px; left: 1px; top: 109px;">Supplier</div>
<div style="position: absolute; visibility: inherit; overflow: hidden; cursor: default; color: rgb(255, 255, 255); background-color: rgb(25, 63, 148); text-align: left; width: 140px; height: 18px; left: 1px; top: 127px;">
<div style="position: absolute; visibility: inherit; overflow: hidden; cursor: default; color: rgb(255, 255, 255); background-color: rgb(25, 63, 148); text-align: left; width: 140px; height: 16px; padding-left: 0px; padding-top: 2px; left: 1px; top: 145px;">Department</div>
<div style="position: absolute; visibility: inherit; overflow: hidden; cursor: default; color: rgb(255, 255, 255); background-color: rgb(25, 63, 148); text-align: left; width: 140px; height: 16px; padding-left: 0px; padding-top: 2px; left: 1px; top: 163px;">Rejection Reason</div>
<div style="position: absolute; visibility: inherit; overflow: hidden; cursor: default; color: rgb(255, 255, 255); background-color: rgb(25, 63, 148); text-align: left; width: 140px; height: 16px; padding-left: 0px; padding-top: 2px; left: 1px; top: 181px;">Exchange Rate</div>
<div style="position: absolute; visibility: inherit; overflow: hidden; cursor: default; color: rgb(255, 255, 255); background-color: rgb(25, 63, 148); text-align: left; width: 140px; height: 16px; padding-left: 0px; padding-top: 2px; left: 1px; top: 199px;">Standard Yield</div>
<div style="position: absolute; visibility: inherit; overflow: hidden; cursor: default; color: rgb(255, 255, 255); background-color: rgb(25, 63, 148); text-align: left; width: 140px; height: 16px; padding-left: 0px; padding-top: 2px; left: 1px; top: 217px;">Production Plan</div>