I am trying to learn selenium with java using ebay.com. I found a difficult element to select element after mouse hover. Here is my snippet code

driver.findElement(By.xpath("//a[contains(text(),'Tennis')]")).click()

However above code return error element not interactable

I have add Thread.sleep(60000) before driver.findElement and still not able to click

here is the window i wanted to click

enter image description here

2

There are 2 best solutions below

0
Sers On

Hover to Sports menu using Actions and when menu opens click to the Tennis submenu. To wait for Tennis to be clickable use WebDriverWait:

WebDriverWait wait = new WebDriverWait(driver, 5);
Actions actions = new Actions(driver);

driver.get("https://www.ebay.com");

WebElement sports = driver.findElement(By.linkText("Sports"));

actions.moveToElement(sports).perform();
wait.until(ExpectedConditions.elementToBeClickable(By.linkText("Tennis"))).click();
0
undetected Selenium On

You need to Mouse Hover over the element with text as Sports and wait for the elementToBeClickable() with text as Tennis and you can use the following solution:

  • Code Block:

    System.setProperty("webdriver.chrome.driver", "C:\\Utility\\BrowserDrivers\\chromedriver.exe");
    ChromeOptions options = new ChromeOptions();
    options.addArguments("start-maximized");
    options.addArguments("--disable-extensions");
    //options.addArguments("disable-infobars");
    WebDriver driver = new ChromeDriver(options);
    driver.get("https://www.ebay.com/");
    new Actions(driver).moveToElement(new WebDriverWait(driver, 10).until(ExpectedConditions.visibilityOfElementLocated(By.linkText("Sports")))).perform();
    new WebDriverWait(driver, 10).until(ExpectedConditions.elementToBeClickable(By.xpath("//a[text()='Sports']//following::div[@class='hl-cat-nav__flyout']//span[text()='Other Categories']//following::ul[1]/li/a[normalize-space()='Tennis']"))).click();
    
  • Browser Snapshot:

ebay