javaselenium-webdriverautomationelement

Element is not interactable through selenium automation


I want to select the "Round Trip" radio button after clicking the "Both" button. However, the website has right-click disabled, and I am receiving an error on SelectorHub stating, "This element is not interactable through Selenium (automation) as it is not visible in the UI." I have tried various wait methods, but I am still unsuccessful. Any help would be greatly appreciated.

public static void main(String[] args) throws Exception 
    {
        WebDriver driver = new ChromeDriver();
        driver.manage().timeouts().implicitlyWait(Duration.ofSeconds(10));
        driver.get("https://dummy-tickets.com/buyticket");
        driver.manage().window().maximize();

        driver.findElement(By.xpath("//a[normalize-space()='Both']")).click();
        Thread.sleep(5000);
        //driver.findElement(By.xpath("//input[@value='roundtripmain']")).click();
        
        WebDriverWait wait= new WebDriverWait(driver, Duration.ofSeconds(10)); 
        WebElement element = wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//input[@value='onewaymain']")));
        element.click();
        
        //*[@id="twotabtabone"]/div/div/div/div/div[1]/label[2]/input
                
        
  }

enter image description here

enter image description here


Solution

  • Try the following.

    
    import java.time.Duration;
    import java.util.logging.Level;
    import java.util.logging.Logger;
    import org.openqa.selenium.By;
    import org.openqa.selenium.WebDriver;
    import org.openqa.selenium.chrome.ChromeDriver;
    import org.openqa.selenium.support.ui.ExpectedConditions;
    import org.openqa.selenium.support.ui.WebDriverWait;
    
    
    public class JavaTest
    {
        public static void main(String[] args)
        {
            try 
            {
                WebDriver driver = new ChromeDriver();
                
                driver.get("https://dummy-tickets.com/buyticket");
                driver.manage().window().maximize();
                driver.getTitle();
                Thread.sleep(1000);
                driver.findElement(By.xpath("//a[normalize-space()='Both']")).click();
                Thread.sleep(2000);
                new WebDriverWait(driver, Duration.ofSeconds(4)).until(ExpectedConditions.elementToBeClickable(By.xpath("//input[@value='roundtripfh']"))).click();
                Thread.sleep(2000);
                new WebDriverWait(driver, Duration.ofSeconds(4)).until(ExpectedConditions.elementToBeClickable(By.xpath("//a[normalize-space()='Flight']"))).click();
                Thread.sleep(2000);               
                new WebDriverWait(driver, Duration.ofSeconds(4)).until(ExpectedConditions.elementToBeClickable(By.xpath("//input[@value='roundtripmain']"))).click();
                //driver.quit();
            }
            catch (InterruptedException ex) 
            {
                Logger.getLogger(JavaTest.class.getName()).log(Level.SEVERE, null, ex);
            }
        }
    }