Retrieve the initial element that shares the same attributes in the XPath query

Currently exploring the website . My goal is to select the first item in the menu that has the attribute

data-selenium='link_front_generic'
.

Here's the code I tried:

 driver.findElement(By.xpath("(.//*[@data-selenium='link_front_generic'])[1]")).click();

Unfortunately, the item cannot be found.

An exception was thrown: org.openqa.selenium.ElementNotVisibleException: element not visible

Answer №1

The content you are trying to access is currently hidden within a menu wrapper that has not been activated.

To solve this issue, you can use the code snippet provided below:

Actions actions = new Actions(driver);
WebElement menu = driver.findElement(By.xpath("//a[text()='Car Parts']"));
actions.moveToElement(menu);

WebElement subMenu = driver.findElement(By.xpath("//a[@title='Brake Pads']"));
actions.moveToElement(subMenu);
actions.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

Utilizing Python to Access Reviews Through Button Clicks

I'm currently attempting to scrape the reviews from this website: . However, I am facing a challenge where I need to click a button (Show more) in order to display all the reviews. <div class="load-more load-more--divider load-more--reviews j ...

When attempting to start a session with a Chrome browser, the WebDriverManager gets stuck in a never-ending loop

After deciding to upgrade the automation infrastructure program, I made the choice to remove the Chrome driver exe from my project. In its place, I wanted to implement a new method that would reduce the need for manual updates whenever Chrome driver needs ...

The secure exchange of HTTP-only cookies between a REST API developed with Spring Boot and a frontend application

Currently, I am in the process of integrating a Spring Boot API with VueJS. Initially, everything was functioning smoothly when I stored the JWT in localstorage. However, numerous online resources suggest that it is advisable to refrain from storing the J ...

Display all hidden locator options for the drop-down element and sequentially select each one from React Bootstrap

We are currently working on a react bootstrap app that includes a Dropdown field. We are attempting to locate the XPath and select a drop down value, but when the drop down value is selected, the HTML does not display the locator or it contains a hidden el ...

Guide to utilizing variables with Pattern.compile in Java for selenium RC

I am facing a challenge where I need to check if the date in a field corresponds to the current day. In Selenium IDE, this is easily achieved: <tr> <td>storeExpression</td> <td>javascript{var date = new Date ...

Combining Jquery Ajax with a Spring Boot controller results in the modification of dates

I am encountering an issue with my Ajax call: $.ajax({ type : 'GET', headers : { Accept : "application/json; charset=utf-8", "Content-Type" : "application/json; charset=utf-8" }, url : ...

Interacting with a hyperlink using the Selenium framework

I am currently working on a project involving scraping data from tandfonline for which I have institutional access. In order to extract the data from each article, I need to click the issue button using the selenium library, which has a unique class or id. ...

Tips on clicking a link inside an iFrame to open a new tab and then navigate to it

I'm currently tackling a project that involves clicking on a link to open it in a new tab using webdriver. However, I've run into some challenges. The link is enclosed within an iFrame, so using shift+click doesn't work as intended. pri ...

Configuring java.home or xml.java.home in Visual Studio Preferences

Welcome I am currently in the process of configuring a Visual Studio code extension that will assist me in generating an XML file according to a specific Schema. The requirements for this extension are as follows: (Please Note: Java JDK 8+ must be insta ...

What is the method for fetching text with neither a node nor attribute using xpath in Selenium?

I am currently attempting to extract specific text from an HTML document using xpath. The structure of the HTML is shown below: The desired "target text" that I want to retrieve is located within a p node. However, this "target text" does not have any s ...

Having trouble generating an XML file within Eclipse

When working in Eclipse, I often encounter a situation where I right click on a project named "WebDriverTest1" and the "Select a Wizard" window appears. However, despite being able to type "xml" in the "Select a Wizard" window, nothing relevant is display ...

Achieving element texts using selenium in headless mode

I'm currently trying to use Selenium in headless mode, where the browser works in the background without opening a visible tab. While my code is able to find elements, it is not displaying any of the text between the tags. Do you have any suggestions ...

Using Python with Selenium to automate clicking the next post button on Instagram

Having trouble navigating to the next post on my Instagram bot. Here are my attempts: #First Attempt next_button = driver.find_element_by_class_name('wpO6b ') next_button.click() #Second Attempt _next = driver.find_element_by_class_name(' ...

Decoding HttpResponse in Android: A Beginner's Guide

I am currently facing an issue with uploading an audio file to my web server and reading the response. Below is a simplified snippet from my test.php file: <?php echo 'I want to see this in the Toast'; ?> Additionally, here is the onC ...

Having trouble initiating a button click using Java Selenium?

HTML code: <button type="button" class="btn btn-main dropdown-toggle" dropdown-toggle="" aria-haspopup="true" aria-expanded="false">create <span class="icon-dir-down"></span> <span class="sr-only">To ...

Java Selenium encountered an error when trying to switch to a detected frame, throwing a NoSuchFrameException and preventing navigation to the frame

Problem Description: I am facing difficulty in navigating to a specific frame using Chrome v92, although it works smoothly in Firefox. Code Example: @Test void auto_015_5() { int bet = 7; driver.navigate().to("https://boa ...

Learn how to implement Data-driven testing in Selenium using Excel or Numbers on a Mac device!

On my Mac machine, I am utilizing Selenium for testing. However, when it comes to data-driven testing using Excel, how can this be done on a Mac since it doesn't have Excel but uses "Numbers" instead, which is similar? ...

Dispensing guarantees with Protractor

q library offers a unique feature that allows resolving and spreading multiple promises into separate arguments: If you have a promise for an array, you can utilize spread instead of then. The spread function distributes the values as arguments in the f ...

What is the best way to manage a multi-select dropdown with checkboxes in Selenium Webdriver?

Below is a snapshot of the drop-down I am working with. In order to handle multiple selections, I currently have code that clicks on the arrow in the drop-down and then selects the corresponding checkbox. However, I would like a more efficient solution fo ...

Issue with Selenium Webdriver: Incorrect display of list items

Within the code snippet provided, I am anticipating a size value of 18 to be displayed, however it is actually showing as 0. The reason behind this discrepancy remains elusive. My current objective involves visiting Amazon in search for books and ultimate ...