繁体   English   中英

为什么我没有使用selenium webdriver选择单选按钮?

[英]Why am failing to select radio button using selenium webdriver?

操作系统:Windows 7 Selenium版本:3.3.1,浏览器:Firefox浏览器版本:47.0.2(64位)

Html Code:



       <div class="radio">
<input id="passwordRadios1" class="password-radio" type="radio" value="guest" name="passwordRadios">
<input type="hidden" value=" " name="_D:passwordRadios">
<label for="passwordRadios1"> No (you can save your details later)</label>
</div>
<div class="form-inline">
<div class="radio">
<input id="passwordRadios2" class="password-radio" type="radio" value="register" name="passwordRadios">
<input type="hidden" value=" " name="_D:passwordRadios">
<label class="radio-inline" for="passwordRadios2">Yes, my password is:</label>
</div>

而我试图选择第一个单选按钮失败使用cssSelectorxpath和所有定位器

driver.findElement(By.cssSelector("#passwordRadios1")).click();

错误

Test Failed
2
Exception in thread "main" org.openqa.selenium.WebDriverException: Element <input name="passwordRadios" id="passwordRadios1" class="password-radio" value="guest" type="radio"> is not clickable at point (168, 431.83331298828125). Other element would receive the click: <div class="loader-overlay" style="opacity:0.9;"></div>
Command duration or timeout: 560 milliseconds
Build info: version: 'unknown', revision: '5234b32', time: '2017-03-10 09:00:17 -0800'
System info: host: 'TWVEN-DES-05', ip: '172.16.24.53', os.name: 'Windows 7', os.arch: 'amd64', os.version: '6.1', java.version: '1.8.0_121'
Driver info: org.openqa.selenium.firefox.FirefoxDriver
Capabilities [{applicationCacheEnabled=true, rotatable=false, handlesAlerts=true, databaseEnabled=true, version=47.0.2, platform=WINDOWS, nativeEvents=false, acceptSslCerts=true, webStorageEnabled=true, locationContextEnabled=true, browserName=firefox, takesScreenshot=true, javascriptEnabled=true, cssSelectorsEnabled=true}]
Session ID: a692e880-f284-47af-9a20-1bcf60d76e63
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
    at java.lang.reflect.Constructor.newInstance(Unknown Source)
    at org.openqa.selenium.remote.ErrorHandler.createThrowable(ErrorHandler.java:216)
    at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:168)
    at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:638)
    at org.openqa.selenium.remote.RemoteWebElement.execute(RemoteWebElement.java:274)
    at org.openqa.selenium.remote.RemoteWebElement.click(RemoteWebElement.java:84)
    at tesPack.Test1Class.main(Test1Class.java:76)

有谁能帮帮我...

请尝试以下代码。

driver.get("file:///C:/Users/Jainish.M.Kapadia/Desktop/aaa.html");
driver.manage().window().maximize();
driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);

driver.findElement(By.id("inputEmail")).sendKeys("test@gmail.com");

WebDriverWait wait = new WebDriverWait(driver, 7);
wait.until(ExpectedConditions.elementToBeClickable(driver.findElement(By.xpath("//input[@id='passwordRadios1']"))));

WebElement no = driver.findElement(By.xpath("//input[@id='passwordRadios1']"));
if(!no.isSelected())
{
    no.click();
}

尝试使用JavascriptExecutor单击元素,如下所示:

WebElement element = driver.findElement(By.xpath("//input[@id='passwordRadios2']"));
((JavascriptExecutor) driver).executeScript("arguments[0].click();", element);

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM