尝试从单选按钮中选择,检查控制台上的元素是否存在并且不在Iframe下:
$x("//*[@id='featuresCollapse1']/div[1]/label/span")
(2) [span.overlay, span.overlay]
超文本标记语言:
<div class="col-6 my-1 feature-input-wrapper text-left">
<input name="radio0" data-index="1" id="Personal Accident for Driver only" hidden="" type="radio"><label data-code="PA-DO" data-value="60" class="radio-inline custom-component featureInput p-0 radio-no form-group">
<span class="overlay" tabindex="0"></span>
<label data-value="60" class="feature-name">Personal Accident for Driver only<span class="option-price font-weight-bold ml-2"> 60 </span> </label></label></div>
收音机的Xpath是:私有最终By PAforDriverOnly=By. xpath("//*[@id='特征折叠1']/div[1]/label/span");
尝试在这里检查它是否显示…但不是“阅读异常消息
try {
driver.findElement(PAforDriverOnly).isDisplayed();
System.out.println("driver.findElement(PersonalAccindent).isDisplayed();");
String Persional = driver.findElement(PAforDriverOnly).getText();
System.out.println(Persional);
driver.findElement(PAforDriverOnly).click();
System.out.println("driver.findElement(PersonalAccindent).click();");
//getTextAct(ProceedToCheckoutBtn);
} catch (Exception e){
System.out.println("The Exception Message of Verify Button : "+e);
}
这里尝试使用JavaScriptExcator,但在WebDriver等上失败,一旦删除它,它读取JavaExcator但没有给出任何操作:
WebElement myElement = driver.findElement(PAforDriverOnly);
new WebDriverWait(driver, 5).until(ExpectedConditions.visibilityOfElementLocated(PAforDriverOnly));
((JavascriptExecutor)driver).executeScript("arguments[0].click();", myElement );
System.out.println("JavaScriptExcutor - Click on RadioButton");
Thread.sleep(2000);
Btnclick(PAforDriverOnly);
我希望你的xpath是错误的,因为你的xpath指向标签。尝试将其指向输入标签。
使用此//input[@id='仅限驱动程序的个人事故']或在查找元素的过程中使用它,但您需要向下钻取到输入标签。