I have a code which clicks on a radio button, at first I was using Chrome. Using the code below:
driver.findElement(By.id("radioButton1"))).click();
I got the error:
"org.openqa.selenium.WebDriverException: Element is not clickable at point (411, 675). Other element would receive the click: ..."
Doing research, I changed the code to:
actions.moveToElement(driver.findElement(By.id("radioButton1"))).click().perform();
Now, I am trying to use Internet Explorer driver. But it does not perform the click.
I tried the following:
driver.findElement(By.id("radioButton1")).sendKeys(Keys.ENTER);
actions.moveToElement(driver.findElement(By.id("radioButton1"))).click().perform();
((JavascriptExecutor) driver).executeScript("arguments[0].click()", driver.findElement(By.id("radioButton1")));
But none works. The first one just focuses on the button, so I added another sendKeys, but it doesn't work. The 2nd and 3rd, nothing happens.
Edit:
Adding HTML snippet.
<input name="btn1" class="w-rdo-native" id="radioButton1" type="radio" value="value1" bh="RDOINP" isrefresh="false">
<label class="w-rdo w-rdo-dsize" bh="RDO"></label>
And when I click on the radio button, the label gets an additional property upon click.
<label class="w-rdo w-rdo-dsize" bh="RDO" AWMouseDown="true"></label>
Additional edit:
The set of buttons look like this:
and as stated before, one button + label block has the following HTML structure:
<tr>
<td>
<div class="w-rdo-container">
<input name="radioButtons" class="w-rdo-native" id="button1" type="radio" value="button1" bh="RDOINP" isrefresh="false">
<label class="w-rdo w-rdo-dsize" bh="RDO">
</label>
</div>
</td>
<td class="sectionHead">Option 2
</td>
</tr>
Upon clicking a button, the corresponding label gets an additional attribute:
<label class="w-rdo w-rdo-dsize" bh="RDO" AWMouseDown="true"></label>
It seems AWMouseDown seems to be the trigger to 'officially' click the button.
Edit :
Full HTML snippet of table. (Please note that this table has been cleansed so apologies for some mistake if I committed one.)
<table border="0" cellpadding="0" cellspacing="0" class="a-cptp-tbl">
<tbody>
<tr>
<td>
<div class="w-rdo-container">
<input checked class="w-rdo-native" id="btn1" name="radioBtn" type="radio" value="btn1"><label class="w-rdo w-rdo-dsize"></label>
</div>
</td>
<td class="sectionHead">Option 1</td>
</tr>
<tr>
<td></td>
</tr>
<tr>
<td>
<div class="w-rdo-container">
<input class="w-rdo-native" id="btn2" name="radioBtn" type="radio" value="btn2"><label class="w-rdo w-rdo-dsize"></label>
</div>
</td>
<td class="sectionHead">Option 2</td>
</tr>
<tr>
<td></td>
</tr>
<tr>
<td>
<div class="w-rdo-container">
<input class="w-rdo-native" id="btn3" name="radioBtn" type="radio" value="btn3"><label class="w-rdo w-rdo-dsize"></label>
</div>
</td>
<td class="sectionHead">Option 3</td>
</tr>
<tr>
<td></td>
</tr>
<tr>
<td>
<div class="w-rdo-container">
<input class="w-rdo-native" id="btn4" name="radioBtn" type="radio" value="btn4"><label class="w-rdo w-rdo-dsize"></label>
</div>
</td>
<td class="sectionHead">Option 4</td>
</tr>
<tr>
<td></td>
</tr>
<tr>
<td>
<div class="w-rdo-container">
<input class="w-rdo-native" id="btn5" name="radioBtn" type="radio" value="btn5"><label class="w-rdo w-rdo-dsize"></label>
</div>
</td>
<td class="sectionHead">Option 5</td>
</tr>
<tr>
<td></td>
</tr>
<tr>
<td>
<div class="w-rdo-container">
<input class="w-rdo-native" id="btn6" name="radioBtn" type="radio" value="btn6"><label class="w-rdo w-rdo-dsize"></label>
</div>
</td>
<td class="sectionHead">Option 6</td>
</tr>
<tr>
<td></td>
</tr>
</tbody>
</table>
We can list the most common reasons for click problems as being one of the following: Wrong web element locations. The existence of a web element that obscures the web element that we want to click. The Selenium WebDriver works much faster than the response of the application.
How to locate a radio button using the name locator? If the radio button contains a unique value in the "name " attribute, then we can use the Name locator of Selenium to locate the radio button. Once located, we can perform click operation on the radio button element to select the radio button.
Once connected using the driver, users can access several web page components like buttons, scroll bars, and other kinds of HTML tags. Selenium provides different functionalities like scrolling pages, searching for elements in pages, clicking website buttons, etc.
Selenium can use multi−threading in one browser with the help of TestNG framework. TestNG provides the feature of parallel execution which works on the concept of Java multi−threading. To execute tests based on various parameters, the TestNG has an XML file where we have the configurations.
Try using JavaScript like below:
WebElement radioBtn1 = driver.findElement(By.id("radioButton1"));
((JavascriptExecutor) driver).executeScript("arguments[0].checked = true;", radioBtn1);
If you are using QMetry Automation Framework, you should create custom radio button component like where you can override click method with such custom implementation.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With