I checked the other posts like this but they weren't able to help me. I'm just starting out with Selenium and I'm having trouble clicking a radio button.
This is what is in the inspector.
input id="createCreds" name="addUser" aria-required="true" ng-model="formData.newUserType" ng-required="addNewUser.$submitted && !formData.newUserType" "="" class="ng-valid ng-valid-required ng-dirty ng-valid-parse ng-touched" aria-checked="true" aria-invalid="false" value="createCreds" type="radio"
Here is what I've tried
Trial 1 :
WebElement userRadioBtn = driver.findElement(By.id("createCreds"));
userRadioBtn.click();
Trial 2 :
driver.findElement(By.xpath("//*[#id="createCreds"]']")).click();
Trial 3 :
driver.findElement(By.id("createCreds")).click();
Trial 4 :
input[#value='createCreds']/following-sibling::label
I was trying to copy this guy around 6 minutes.
https://www.youtube.com/watch?v=BKbzW4S2qQ0
I was hoping to find something like Click RadioButton css=#createCreds or xpath=//*[#id="createCreds"]
As per the HTML you have shared to click on the Radio Button as the element is an Angular element you have to induce WebDriverWait and you can use either of the following options as follows :
cssSelector :
new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.cssSelector("input.ng-valid.ng-valid-required.ng-dirty.ng-valid-parse.ng-touched#createCreds"))).click();
xpath :
new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.xpath("//input[#class='ng-valid ng-valid-required ng-dirty ng-valid-parse ng-touched' and #id='createCreds']"))).click();
Related
I have button in our website, and border areas of the button is not clickable. So, i need to make sure the button is getting clicked at the center. Is it possible via selenium?
I tried using coorinates, but it is not recommended for our scenario.
xpath used : //div/button[#id='clickme']
<div class="col-lg-10 col-sm-12 p-0 pt-4">
<button class="click mb-3 " tabindex="0" id="clickme">+ Click Here</button>
</div>
Java code used to click
WebElement button = driver.findElement(By.id("clickme"));
button.click();
I guess the click is happening sometimes[2 out of 10 times] on the border where it is not clickable(hand symbol not shown) . As a result report says the click action happened, but there is no event fired on the website.
To identify the element with text as Click Here you can use either of the following Locator Strategies:
cssSelector:
"button.click#clickme"
xpath:
"//button[contains(#class, 'click') and #id='clickme'][contains(., 'Click Here')]"
This question already has answers here:
Element MyElement is not clickable at point (x, y)... Other element would receive the click
(5 answers)
Closed 3 years ago.
I try to select checkbox via chrome webdriver, but always get error like "Element is not clickable at point (x, y)". I use the latest ChromeDriver 2.35. Thanks for help!
Here are the calls I have tried"
driver.findElement(By.xpath("/html[#class='ng-scope']/body[#class='layout-default']/main[#class='container']/form[#class='form-horizontal ng-pristine ng-valid ng-valid-required']/div[#class='row ng-scope']/div[#class='col-md-7']/div[#class='panel panel-default ng-scope']/div[#class='panel-body'][1]/div[#class='list-permission'][1]/div[#class='checkbox'][1]/label")).click();
OR
driver.findElement(By.cssSelector("input[value='platform:AccessWebsite']")).click();
OR
driver.findElement(By.xpath("//input[#value='platform:AccessWebsite']")).click;
Here is the snippet of html source
<h2>Main Platform</h2>
<div class="list-permission">
<div class="checkbox">
<label>
<input name="Policy[0][Action][]" type="checkbox" value="platform:AccessWebsite">
Access to the website
</label>
</div>
.......
When the element is not in a visual portion of the screen, then we will get element not clickable exception. The solution for this is moving the cursor to that element or scrolling the screen.You can use Actions class to move to that element or javascript executor for scrolling. try the below code and let me know.
WebElement element=driver.findElement(By.xpath("/html[#class='ng-scope']/body[#class='layout-default']/main[#class='container']/form[#class='form-horizontal ng-pristine ng-valid ng-valid-required']/div[#class='row ng-scope']/div[#class='col-md-7']/div[#class='panel panel-default ng-scope']/div[#class='panel-body'][1]/div[#class='list-permission'][1]/div[#class='checkbox'][1]/label"));
Actions act= new Actions(driver);
act.moveToElement(element).click().build().perform();
This should work as expected.
Note: some browsers may not support actions class, in such case i suggest you to scroll the screen and perform click.
I have an HTML code as follows:
<label class="top" for="id_gender2">
<div id="uniform-id_gender2" class="radio">
<span>
<input id="id_gender2" type="radio" value="2" name="id_gender">
</span>
</div>
Mrs.
</label>
The radio button is getting selected after mouse hover.
I have tried with all possible attributes for selection but I am getting element not found exception.Please let me know how to write java script in webdriver.
Try following code and let me know the result:
Actions action = new Actions(driver);
WebElement hover = driver.findElement(By.xpath("//*[#class='radio hover']"));
action.moveToElement(hover).moveToElement(driver.findElement(By.xpath("//input[#id='id_gender2']"))).click().build().perform();
UPDATE
Actually there is no need in mouse hover. Target radio seem to be initially non-clickable, so you just need extra time to wait for page complete rendering:
WebDriverWait wait = new WebDriverWait(driver, 15);
wait.until(ExpectedConditions.elementToBeClickable(By.cssSelector("input#id_gender2")));
driver.findElement(By.cssSelector("input#id_gender2")).click();
Try javascript executor as follow:
WebElement element = driver.findElement(By.id("id_gender2"));
((JavascriptExecutor) driver).executeScript("arguments[0].click();", element);
Your element is probably not loaded properly while getting error. You'd better use explicit wait in your script. Wait until your specific element loaded to be visible/clickable. I think, this may help you.
Code snippet:
By yourElementToSelect = By.id("id_gender2");
WebDriverWait wait = new WebDriverWait(driver, 20);
wait.until(ExpectedConditions.visibilityOfElementLocated(yourElementToSelect));
driver.findElement(yourElementToSelect).click();
I'm new to selenium. I was trying to select radio button from a form. It has id. By.id("test12")).getAttribute("value")), displays the correct value,but if i do By.id("test12")).click(); did not click the element.
driver.findElement(By.xpath("//*#id='test13']")).getAttribute("Value"));
also displays the name. but click() didn't work.
I got org.openqa.selenium.ElementNotVisibleException: Element is not currently visible and so may not be interacted with
Command duration or timeout: 30.09 seconds
<input id="test12" class="with-gap" type="radio" value="P" name="group1">
<input id="test13" class="with-gap" type="radio" value="C" name="group1">
List<WebElement> eRB=driver.findElements(By.name("group1"));
System.out.println(eRB.size());
for(int i=0;i<eRB.size();i++)
{
System.out.println(eRB.get(i).getAttribute("id")+" is Displayed = "+eRB.get(i).isDisplayed());
}
the o/p was:
4
test13 false
test12 false
test13 false
test12 false
Could anyone tell what i'm doing wrong? Thanks.
#Suba Narayanan, use webdriver wait to check the visibility of the element before clicking.
WebDriverWait wait = new WebDriverWait(driver, 30);
wait.until(ExpectedConditions.elementToBeClickable(By.id("test12"))).click();
Try the below code for clicking the radio button:
driver.get("https://www.jobsforher.com/employer/account/sign_up");
Thread.sleep(5000L);
driver.findElement(By.xpath("//*[#id='test2']/div/div/div[1]/div[1]/div[2]/div/label")).click();
Thread.sleep(5000L);
You can customise your wait by waiting for specific element.
Let me know for more queries.
Happy Learning. :)
I am unable to select radio button in Selenium Webdriver-Java with given html code
<input id="idcc-de81e53f-7cfd-4136-816f-d09d4055eeee" type="radio" value="de81e53f-7cfd-4136-816f-d09d4055eeee" name="panels:0:panel:stepContainer:stepTypeDisplay:optionPanel:options">
<label for="idcc-de81e53f-7cfd-4136-816f-d09d4055eeee">Canada</label>
<br>
<input id="idcc-17c1d432-5cec-4da9-9a02-39986d508770" type="radio" value="17c1d432-5cec-4da9-9a02-39986d508770" name="panels:0:panel:stepContainer:stepTypeDisplay:optionPanel:options">
<label for="idcc-17c1d432-5cec-4da9-9a02-39986d508770">United States</label>
id="idcc-de81e53f-7cfd-4136-816f-d09d4055eeee" most likely to by dynamic id so what you need to do is something like
option 1:
List<WebElement> radioButtons = driver.findElements(By.xpath("//input[#type='radio']"));
foreach(IWebElement button : radioButtons)
{
if(button.getText.Equels("Canada"))
{
button.cilck();
}
}
option 2:
driver.findElement(By.partialLinkText("Canada")).click();
Hi please do it like below
driver.get("file:///C:/Users/rajnish/Desktop/radio.html");
driver.manage().window().maximize();
// for canada
driver.findElement(By.id("idcc-de81e53f-7cfd-4136-816f-d09d4055eeee")).click();
// for United states
driver.findElement(By.id("idcc-17c1d432-5cec-4da9-9a02-39986d508770")).click();
what issues you were facing in doing this its very simple and straight ,please post your sample code that you have tried so that i can help you were you were doing it wrong thanks