Attempting to navigate a menu by hovering over it and selecting a link from the sub-menu, only to be met with unsuccessful results

I'm currently practicing how to hover over a menu and then click on a link in the sub-menu.

For this exercise, I need to visit the URL "", hover over "Hello Sign in", and finally click on the link labeled "Start here".

I've managed to successfully hover over "Hello Sign in" using moveToElement(), which triggers the opening of the sub-menu. However, I encountered some difficulty when trying to click on the "Start here" link.

Below is the code snippet that I have been working with:

WebElement signUp = driver.findElement(By.id("nav-link-yourAccount"));
Actions action = new Actions(driver);
action.moveToElement(signUp).build().perform();

WebElement startHere = 
wait.until(ExpectedConditions.visibilityOfElementLocated(By.linkText("Start here")));
startHere.click();

Answer №1

In your code, make sure to include the dot at the end of the link text. You can use By.linkText("Start here.") or By.partialLinkText("Start here") for accurate results.

Answer №2

Try out the modified code provided below, which should work as expected. Begin by locating the new Customer Div and then accessing the start link directly:

WebElement signUp = driver.findElement(By.id("nav-link-yourAccount"));
Actions action = new Actions(driver);
action.moveToElement(signUp).build().perform();

WebElement newCustomer=driver.findElement(By.id("nav-flyout-ya-newCust"));
newCustomer.findElement(By.xpath(".//a")).click();

Answer №3

If you want to visit the website https://www.amazon.in, simply hover your mouse over Hello Sign in and then click on the link Start here.. To achieve this, you need to utilize WebDriverWait for the element containing the text Hello Sign in to become visible. After that, perform a Mouse Hover action on it and wait for the element with the text Start here. to be clickable using another WebDriverWait. Here is a sample solution:

  • Code Block :

    System.setProperty("webdriver.gecko.driver", "C:\\Utility\\BrowserDrivers\\geckodriver.exe");
    WebDriver driver = new FirefoxDriver();
    driver.get("https://www.amazon.in/");
    WebElement signUp = new WebDriverWait(driver, 10).until(ExpectedConditions.visibilityOfElementLocated(By.id("nav-link-yourAccount")));
    new Actions(driver).moveToElement(signUp).build().perform();
    new WebDriverWait(driver, 10).until(ExpectedConditions.elementToBeClickable(By.linkText("Start here."))).click();
    
  • Browser Snapshot :

https://i.stack.imgur.com/7GhWJ.png

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Behat Mink fails to locate file during upload submission

I'm currently testing image uploads using Selenium/Mink with Behat in a Symfony application running within a Docker container. Instead of using $driver->attachFileToField('#id-of-input', $filePath), I am attaching the file directly to th ...

Struggling with issues during the testing of your Yii application on Selenium?

I am currently using selenium-server-standalone-2.44.0.jar to conduct tests on my Yii application. When I run it in the console without any parameters: java -jar selenium-server-standalone-2.44.0.jar I encounter a few issues: Firefox hangs.In the c ...

Access the freshly launched URL

I am relatively new to PHP and have a table displayed on my webpage. Each row in the table has an auto-incremented rowid that is not being displayed. When clicking on a row, it opens a new page in the format of www.newpage.com/newpage/rowid. If I inspect ...

The functionality of Selenium is not supported on Firefox 57 when using php

After installing Selenium Server Standalone 3.9.1, XAMPP 3.2.2, php-webdriver 0.9.1, and Firefox 57, I attempted to execute the example.php file located in the root of the selenium folder. The code snippet is as follows: require_once "phpwebdriver/WebDriv ...

The action cannot be executed with more than one method argument specified

Whenever I try to utilize one of the standard PHPUnit Selenium assertions, the test fails and an error message is displayed: Error: Command cannot have multiple method arguments. The correct usage according to is: void assertElementValueEquals(string $ ...

Launching a new tab in Google Chrome using Selenium for Facebook login with PHP WebDriver

Hey there! I'm diving into the world of Selenium using Facebook's PHP Webdriver and feeling a bit lost. I've been trying to figure out how to open a new tab in Chrome with this technology, but haven't had any luck. Any insights or tips ...

Getting started with Codeception may not always be straightforward: [PHPUnitFrameworkException] Error encountered - Element index not defined

After following the Codeception Quick Start instructions diligently, I proceeded to run the initial example test using PhpBrowser... # Codeception Test Suite Configuration # # [further comments omitted] # actor: AcceptanceTester modules: enabled: ...

Using Selenium to identify and recognize different color patterns

Is it feasible to use Selenium (preferably in combination with PHPUnit Selenium) to detect colors on a webpage? I have banners on my site, and some of them do not reload properly. It's strange because I can access their elements, but all I see on the ...

Unable to locate the addEventListener function when utilizing php webdriver and selenium

I have been working with the webdriver for just three weeks now, and I've come across an issue regarding finding addEventListener. My setup includes using the selenium standalone server in combination with a PHP framework developed by Facebook. My g ...