1

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

1 Answer 1

2

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);
        }
    }
}
Sign up to request clarification or add additional context in comments.

4 Comments

Thank you so much. It worked. Could you tell me how you get the value "roundtripfh" for the selector? I couldn't find this value.
When I just changed "Both" to "Flight", I still get the exception " org.openqa.selenium.TimeoutException: Expected condition failed: waiting for element to be clickable:"
Open the URL in Chrome and go to developer mode. Some of the attributes have the same name, so you are probably running into conflicts.
I updated the code. I also put pauses so that you can see things happen. Selenium does not recommend using implicit and explicit waits in the same code. See selenium.dev/documentation/webdriver/waits

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.