Checkout our demo site to practice selenium https://magento.softwaretestingboard.com/

0 like 0 dislike
1.5k views
in Selenium by
recategorized by
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 like 0 dislike
by
selected by
 
Best answer

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");
    }
0 like 0 dislike
by

Try below xpath.

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

It should work.

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

 


This site is for software testing professionals, where you can ask all your questions and get answers from 1300+ masters of the profession. Click here to submit yours now!

...