Reputation: 91
this is HTML, i just want to test it through selenium web driver(java). there is an error
Exception in thread "main" org.openqa.selenium.ElementNotVisibleException: element not visible
May be below HTML will help you to understand my question
<html>
<head></head>
<body>
<ul class="list-unstyled">
<li>
<label class="chkbox">
<input type="radio" required="required" data-optioncode="displayDefaultForm" data-statusid="22" data-module="19" name="status">
<span class="lbl"></span>
</label>
<button class="btn module-status-style btn-xs mb5" style="background-color: #ffffff; border-color: #e1e1e1; color:#666666;">Unqualified</button>
</li>
<li>
<label class="chkbox">
<input type="radio" required="required" data-optioncode="displayDefaultForm" data-statusid="23" data-module="19" name="status">
<span class="lbl"></span>
</label>
<button class="btn module-status-style btn-xs mb5" style="background-color: #e4e7ea; border-color: #cccccc; color:#636e7b;">Attempted to Contact</button>
</li>
<li>
<label class="chkbox">
<input type="radio" required="required" checked="" data-optioncode="displayDefaultForm" data-statusid="24" data-module="19" name="status">
<span class="lbl"></span>
</label>
<button class="btn module-status-style btn-xs mb5" style="background-color: #5bc0de; border-color: #46b8da; color:#ffffff;">Contacted</button>
</li>
<li>
<label class="chkbox">
<input type="radio" required="required" data-optioncode="displayConvertedForm" data-statusid="25" data-module="19" name="status">
<span class="lbl"></span>
</label>
<button class="btn module-status-style btn-xs mb5" style="background-color: #1caf9a; border-color: #17a08c; color:#ffffff;">Converted</button>
</li>
</ul>
</body>
</html>
please help me to check radio button through java selenuim
Upvotes: 1
Views: 746
Reputation: 66
I have the following approach for your query:
Use xpath://input[@type='radio']
Code:
WebElement ele = driver.fidnElement(By.xpath("//input[@type='radio']"));
ele.click();
Try the above approach.
Upvotes: 1
Reputation: 2149
I can think of two scenarios why your radio buttons are not visible.
The general solutions are:
1: If your radio button is not visible by the time your script clicks on it: you will need to wait for it to appear,
WebDriverWait wait = new WebDriverWait(webDriver, timeoutInSeconds);
wait.until(ExpectedConditions.visibilityOfElementLocated(By.cssSelector("input[type='radio']"));
2: If your radio button is hidden, you need to somehow make it appear, I do not know how exactly your webpage will look like so you will have to figure this out on your own OR show us your webpage.
Upvotes: 0
Reputation: 11
As Saurabh said there is no element present in your code with id frm-modulestatuses. I have checked your code and for clicking the radio button you can simply use xpath =.//ul/li[4]/label/input ,where li[4] for last button as -Xpath showing button and its working
Upvotes: 1
Reputation: 23805
According to your provided HTML you should try as below to select a radio :-
String textToFindRadio = "Unqualified"
//you can provide also "Attempted to Contact" or "Contacted" or "Converted" to select that specific radio.
driver.findElement(By.xpath("//input[@type = 'radio' and (following::button[contains(text(), '" + textToFindRadio + "')])]")).click();
Hope it will work...:)
Upvotes: 1
Reputation: 792
The exception means that the element is not visible. Selenium cannot act on elements that are not visible, since it is intended to emulate user behavior. Check your CSS styles and ensure that the element you are trying to click is visible. If you need to click a hidden element, use JavascriptExecutor to execute a JavaScript click directly.
Upvotes: 1