I am trying to run a test script that will click a radio button. The radio button elements are inside a div.
Here is the javascript code:
var driver = new Builder().forBrowser("chrome").build();
await driver.get("URL");
var selectGender = driver.findElement(By.css("div[class='gender-select-child'] label[for='male-child0']"));
await selectGender.click();
HTML snapshot:
Hoping for a resolve.
To click on the radio-button with text as Male you can use either of the following locator strategies :
var driver = new Builder().forBrowser("chrome").build();
await driver.get("URL");
var selectGender = driver.findElement(By.css("div[class='gender-select-child'] input[id^='male']"));
await selectGender.click();
I was able to click the radio button using this syntax...
await driver.findElement(By.css("label[for='female-child0']")).click();
However, I need to use it twice for it to work. My script looks like this...
Any idea why?
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.