无法点击单选按钮-硒



尝试从单选按钮中选择,在控制台检查元素在那里,它不在Iframe下:

$x("//*[@id='featuresCollapse1']/div[1]/label/span")
(2) [span.overlay, span.overlay]

HTML:

<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是:private final By PAforDriverOnly = By.xpath("//*[@id='featuresCollapse1']/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);
}

和这里尝试使用JavaScriptExcutor,但在WebDriverWait上失败,一旦删除它,它读取javaexecutor而不是Give any Action:

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指向label。尝试将其指向input标签。

use this//input[@id='Personal Accident for Driver only']或者在查找元素的过程中使用它,但需要向下钻取到input标签。

最新更新