简体   繁体   中英

Why am failing to select radio button using selenium webdriver?

OS: Windows 7 Selenium Version: 3.3.1, Browser: Firefox Browser Version: 47.0.2 (64-bit)

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>

while am trying to select first radio button am failing using cssSelector , xpath and all locators

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

Error

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)

Could anyone please help me...

Try this below code.

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();
}

Try using JavascriptExecutor to click on the element as below:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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