I have 2 radio options for Address fields like yes or no, by default US Address option selected for this Zip code field will display, When I click radio option on 'no' then zip code field will be hidden. So I need the code to handle the radio options for above scenario.
// US address - this is working fine as default radio selected to"yes"
WebElement radio = driver.findElement(By.id("usid"));
radio.isSelected();
driver.findElement(By.id("uszipcode")).sendKeys("1234");
driver.findElement(By.id("submit")).click();
//non US Address- (having issues here)
driver.findElement(By.id("nonusid")).click();
driver.findElement(By.id("submit")).click();
I should be able to click from default radio option "yes" to "no" then submit should work
Try if..else block to achieve that.
WebElement radio = driver.findElement(By.id("usid"));
if(radio.isSelected())
{
WebElement radio1 = driver.findElement(By.id("usid of NO radio Button"));
radio1.click();
driver.findElement(By.id("submit")).click();
}
else
{
driver.findElement(By.id("uszipcode")).sendKeys("1234");
driver.findElement(By.id("submit")).click();
}
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.