The hover functionality is not functioning as expected on the demo website when using Selenium WebDriver

I have attempted to use the following code.

public class LocateMultipleItems {
    public static void main(String[] args) {
        WebDriver driver = new FirefoxDriver();
        driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);
        driver.manage().window().maximize();
        driver.navigate().to("http://automationpractice.com/index.php");
        Actions act = new Actions(driver);
        WebElement women = driver.findElement(By.xpath("//*[@id='block_top_menu']/ul/li[1]/a"));
        //women.click();
        Point p1 = women.getLocation();
        int x = p1.getX();
        int y = p1.getY();
        System.out.println("X:"+x+" Y:"+y);
        act.moveByOffset(x, y).click(driver.findElement(By.linkText("T-shirts"))).build().perform();

    }
}

https://i.stack.imgur.com/TYHUf.png

I am attempting to select the "T-shirts" link within the women category. However, I am experiencing difficulty in clicking the link using Mouse hover Actions.

Answer №1

Here is an example of code that you can use:

WebDriver driver = new FirefoxDriver();
driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);
driver.manage().window().maximize();
driver.navigate().to("http://automationpractice.com/index.php");
 driver.manage().timeouts().implicitlyWait(3, TimeUnit.SECONDS);

WebElement women = driver.findElement(By.cssSelector("ul>li:nth-child(1)>a[title='Women']"));

Actions builder = new Actions(driver);  
builder.moveToElement(women).perform();//this will hover to women
Thread.sleep(1000);//it's recommended to avoid using this type of wait. Instead, try waiting until a certain condition is met.

driver.findElement(By.cssSelector("ul>li:nth-child(1)>a[title='T-shirts']")).click();//this will click on t-shirt

This snippet should assist you with your task.

Answer №2

If you are already giving the X and Y coordinates, there's no need to also include the

driver.findElement(By.linkText("T-shirts"))
. Simply try without it and it should work just fine.

Answer №3

There is currently no element identified as By.linkText("T-shirts")

Actions act = new Actions(driver);
WebElement womenLink = driver.findElement(By.xpath("//a[@title='Women']"));
act.moveToElement(womenLink).click().build().perform();
WebElement tshirtLink = driver.findElement(By.xpath("//[@class='sfHoverForce']//a[@title='T-shirts']"));
act.moveToElement(tshirtLink).click().build().perform();

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

Alert for Certification Warning while using Selenium, Python, and Marionette

I am currently working on automating the transfer of a backup file from a (local) headless data server to a (remote) secure backup server. Due to certain requirements, this process has to be carried out through a web page. I have developed a Selenium/Pyth ...

Configuring Firefox profiles with Selenium

Could you assist me in configuring my Firefox profile with Firebug? I am looking to have the Firebug add-on automatically loaded with Firefox when initiated through Selenium WebDriver. Below is a snippet of my code: final File file = new File("C:\&bs ...

Is there a way for me to view the table and information on this website?

Currently, I am in the process of extracting specific data from a table on the following website: . To achieve this, I have opted to use Python along with selenium. The issue arises when attempting to extract the table using read_html() from pandas. Unfor ...

Utilizing Selenium Webdriver in Java to read and write JSON files

Currently, I am developing an Automation Framework and exploring alternatives to using Excel for storing test data, element locators, and page objects. A friend of mine who is also working on Automation suggested using a JSON file to store all the require ...

Finding the input box with C# Selenium: A step-by-step guide

Looking for the input box in this block of HTML: <div id="employeesDataTable_filter" class="dataTables_filter"> <label> <input type="search" class="form-control input-sm" placeholder="Filter..." aria-controls="employeesDataTable"> </l ...

Logging with Selenium WebDriver

I am currently implementing selenium-server and phantomjsdriver in my Java project. <dependency> <groupId>org.seleniumhq.selenium</groupId> <artifactId>selenium-server</artifactId> <version>2.44.0</versio ...

Warning: The use of executable_path is no longer recommended. Please instantiate a Service object instead. How can I proceed?

from bs4 import BeautifulSoup import requests from selenium import webdriver from selenium.webdriver.firefox.firefox_binary import FirefoxBinary from selenium.webdriver.common.desired_capabilities import DesiredCapabilities import time from selenium.webdri ...

Whenever I execute the script, it keeps publishing only the first row from the CSV file repeatedly

I need assistance with a script I have created to upload images to a website from a CSV file. However, each time I run the script, it only uploads the first row of data. Here is an excerpt from the script where I attempt to publish all images, descripti ...

When attempting to subtract values, Python is unable to directly convert a string to a float

I've been attempting to convert the string "2,900.99" into a float unsuccessfully with both float(int("2,900.99")) and float("2",900.99"). The data is being extracted from selenium and beautiful soup, and it's currently in string format. I'm ...

Issues with using send_keys in Selenium Python

I'm currently facing an issue with sending keys in a Selenium search box while automating scripts in Python. Here is the code snippet causing the problem: contact_old = driver.find_element_by_class_name("consoleRelatedRecord") time.sleep(2) search_ ...

Steps to troubleshoot the issue of "Your Firefox profile cannot be loaded. It may be missing or inaccessible" when working with Selenium

I am trying to utilize selenium with geckodriver. After installing Firefox and Geckodriver, I attempted to run a simple selenium application but encountered an error dialog box. Here is my code snippet: public static void main(String[] args) throws Malfo ...

Working with Parallel Threads in C# for Selenium Automation

Seeking to automate the testing process for one of my websites using Selenium with C#. The website requires user login credentials and must be accessed through multi-threading. One thread is used to open the page in a specialized Firefox profile, while ano ...

HtmlUnitDriver fails to execute javascript while loading a page from a URL

My issue revolves around testing my website page, where elements displayed with javascript are missing when viewed through the HtmlUnitDriver. I am currently using selenium-java version 3.141.59 and htmlunit-driver version 2.33.3. Below is a snippet of my ...

Utilizing JsonNode from Jackson library in Java for parsing nested JSON data can sometimes lead to NullPointerExceptions

I've been struggling to make this parser work properly for some time now, encountering the same issue repeatedly. The code consistently returns a value of null. The problem lies in a call to the Google Books API, which returns a large JSON response w ...

Encountering NoSuchElementException while utilizing Xpath

Hey there! I've been attempting to navigate this website and I'm hoping to automate the process by applying some filters through a click. However, when I try to use the find_element_by_xpath function, it's coming up as deprecated. Can anyone ...

Could not find the Python Selenium ID in the system

I'm currently utilizing Selenium in Python to automatically input the username on a web browser. However, I encountered an issue where it couldn't locate the ID. Strangely enough, it worked perfectly fine on the Bing website but failed on this pa ...

Automating the WebDriver script in JMeter with advanced tools

Are there any tools available that can assist in creating automation scripts for WebDriver within JMeter? ...

Response with a JSON arraylist is returned

I am relatively new to JSON and jQuery, and I am trying to retrieve JSON data using AJAX. My goal is to display this data upon clicking a submit button. Here is the code snippet that I attempted: PrintWriter out = response.getWriter(); List<Countries&g ...

What is the best way to extract a specific section of a webpage element using Python and Selenium?

I'm looking to extract the string '/echipa/lok-moscova/Sjs63WfK' that comes after window.open from this specific web element using selenium, but I'm unsure of how to achieve it. <a href="#" class="participant-imglink&q ...

Is there a way to confirm that the amount of rows in the table aligns with the number of times the ADD button has been clicked?

Is It Possible to Ensure the Number of Rows in a Table Matches the Number of Additions Made by Clicking the ADD Button? At first, the table may look something like this... view initial image here Then, additional data needs to be added as rows to the ta ...