Join 500+ Software Testing professionals. Solve problem and get your problem solved. Register Now!

0
How to click on a radio button in Selenium Webdriver

Solved 2 Answers 520 Views Selenium
0 2
I am automating makemytrip.com website. I am not able to click on "One Way" radio button. I have written below code
 
 
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
 
public class TryRadioClass {
 
    public static void main(String[] args) {
        System.setProperty("webdriver.chrome.driver", "Chrome exe path");
        WebDriver driver=new ChromeDriver(); 
        driver.manage().window().maximize();
        driver.manage().timeouts().implicitlyWait(45, TimeUnit.SECONDS);
        WebElement element=driver.findElement(By.linkText("ONE WAY"));
        element.click();
        System.out.println("Tried to click One Way");
    }
 
}

2 Answers

0
Best answer
0

Use below code :-

        try{
        Thread.sleep(5000);
        }
        catch(Exception ex)
        {
    
        }
        WebElement element=driver.findElement(By.xpath("//span[@class='radio_state']"));
        JavascriptExecutor executor = (JavascriptExecutor) driver;
        executor.executeScript("arguments[0].click();", element);
        System.out.println("Tried to click One Way");
    }
answered by
selected by
0
0

Try below xpath.

//*[@id="one_way_button1"]/span/input

It should work.

driver.findElement(By.xpath(//*[@id=\"one_way_button1\"]/span/input)).click();

 

answered by

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.
Anti-spam verification:
To avoid this verification in future, please log in or register.
...