What is the best way to retrieve all "a" elements with the "title" attribute from a list item?

How can I retrieve the Title values of all the a tags? Below is the XML structure with a ulTopMenu that acts as a hover dropdown, and I am using Protractor.

<ul id="ulTopMenu">
<li>
<li>
<li>
    <ul class="submenu">
        <li>
            <a href="" title = "test2"></a></li>
        <li>
            <a href ="" title = "test1" ></a></li>
    </ul>
 </li>
</ul>

This is what I have attempted so far:

var menus = element.all(by.css('#ulTopMenu > li'));
    var submenu = element.all(by.css('#ulTopMenu > li .submenu li')).all(by.tagName('a'));
    browser.actions().mouseMove(menus.get(3)).perform().then(function () {
        submenu.filter(function (elem, index) {
            return elem.getAttribute('title').then(function (val) {
                return val === 'test1'
            })
        }).first().click();

However, I keep getting an error indicating that the element is not visible.

Answer №1

When troubleshooting code, it can be challenging without actually running the code to see what's going on. However, based on my experience, here is a suggestion - perhaps you should start by opening the dropdown itself:

var dropdown = element(by.id("ulTopMenu"));
var submenu = dropdown.$("ul.submenu");
var desiredMenuItem = submenu.$('li > a[title=test1]');

browser.actions()
    .mouseMove(dropdown)
    .mouseMove(submenu)
    .click(desiredMenuItem)
    .perform()

I used a CSS selector to locate the link by its title.

Additionally, consider the assumptions I made when performing the actions - check if the dropdown needs to open via mouse move or click.

You may also want to include delays between actions - we have utilized a custom sleep() browser action in similar scenarios.


If your goal is simply to extract the link texts with the attribute title:

$$("#ulTopMenu ul.subMenu li > a[title]").getText().then(console.log);

Answer №2

It is essential to note that the error message is accurate. When dealing with a drop-down menu, submenus typically appear after you click on the main drop-down option. This sequential process ensures that the submenu becomes visible and allows for interaction with specific submenu items.

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

Extract information from a webpage using Selenium

There are various tags present on a page, like the following: <tr class=" ev_modern"> <td align="left" valign="middle" title="1">1</td> <td align="left" valign="middle" title="09:00:08" class="">09:00:08</td> <td align= ...

in Selenium, locate the immediate sibling of an element that contains a specific child element identified by a CSS selector

I am attempting to target a specific element within a table structure like the one below: <table> <tbody> <tr> <td> <span>MySpan1</span> </td> <tr> <tr> <td> </td> <td> <di ...

Encountering Problems with Dependencies in Selenium Webdriver 2.20 for .Net Client?

Currently facing a strange issue as I begin working on some acceptance tests and tried to NUGet the latest Selenium Webdriver. Installation went smoothly, and I quickly wrote a test to ensure everything was functioning: [Test] public void should_navigate_ ...

Obtaining the attribute value of a disabled element in an Angular JS application

Currently, I am struggling to retrieve the attribute value of a disabled element during runtime and then assert its value. The code I'm using is not providing the desired result: softAssert.assertFalse(shrSub.nextButton().waitForPresent().getAttribu ...

How to patiently wait for AngularJS to complete updating the DOM post AJAX requests in Selenium?

[Related philosophical debate about the benefits of simply sleeping it out on programmers.se] Angular doesn't always update the DOM completely in the AJAX completion event handler (especially with third-party directives), so many of the solutions fou ...

Automating desktop applications using web technologies through Selenium WebDriver with NW.js and the Chromium Extended Framework

I am currently in the process of automating my standalone desktop application, which is built using web technologies and integrated with the Chromium Embedded Framework via NW.js. The application I am testing is a desktop-based implementation utilizing we ...

Extracting text content from an element with xpath

I am trying to create an assert statement to compare the expected text with the actual one. In order to do this, I need to extract the text from a specific element in the HTML code provided below: <div class="checkout-list"> <div class ...

Unable to access SVG element in a loop and retrieve all the contents

My goal is to extract job titles from a job-site by scraping the information. I want to navigate to the subsequent pages, extract the data, and continue until no more pages are available. However, when attempting to click on the next page marked as an svg ...

Difficulty with automating tests using selenium in Linux: Unable to automatically close Firefox browser

When conducting automation testing for web GUI in Linux using Selenium (Selenium RC), I encountered an issue. While running Selenium tests on Windows yielded successful results with Firefox closing automatically after completing the test, the same could no ...

Which UI testing tool in the .NET framework includes a built-in browser for quicker test execution?

Hey there! I have a vague memory of either selenium or watin having their own browser built-in to speed up test runs compared to using the regular browsers like IE or Firefox. Can someone point me in the right direction for more information or documentatio ...

Tips on launching a Windows service beyond Session 0

My current setup includes a Selenium Grid with its hub and nodes (VMs) set up as Windows services. However, I have encountered an issue where I am unable to visually inspect how a test runs within a browser on a specific node because nothing actually appea ...

Issues with Selenium getting stuck while using pyvirtualdisplay

Running Selenium with Python on a server requires the ability to hide the Chrome display. Most of the time, the Python script runs smoothly, but occasionally it gets stuck when creating a new chromedriver session. It's puzzling why this happens interm ...

Using Selenium WebDriver to Extract Variables from JavaScript SourceCode

Currently, I am dealing with a web page source code that utilizes JavaScript to display text. Below is an excerpt from the source: var display_session = get_cookie("LastMRH_Session"); if(null != display_session) { document.getElementById("sessionDIV") ...

Transferring Text from PDF to Clipboard using Selenium

Looking to extract text from a PDF link that opens in a browser using the chrome built-in PDF viewer. We're trying to avoid using PDFBox or downloading the file locally for verification. We attempted using Keys.chord to send "CTRL+A" and "CTRL+C" (bo ...

Updating the download destination in Microsoft Edge with Python and Selenium

Is there a way to change the download directory for Python Selenium in Chrome? DownloadPath = (f'C:\\Users\\{EmplyID}\\Desktop\\General Orders\\{Newfolder}') chromeOptions = Options() chro ...

Is it possible to upload an allure report to a Sharepoint site using Python code and then share the HTML link via email?

Is there a way to automatically copy my allure report folder to the Sharepoint site and share the html report link with my team via email? Unfortunately, I do not have access to AWS in my company, so using an S3 bucket is not an option. Thank you! ...

The Pyautogui library appears to be malfunctioning when used in a CMD program

My goal is to automate a CMD program by utilizing the on-screen keyboard where the "+" sign is located at coordinates (1874,919). In the code snippet provided below, I attempt to move the cursor to the specified location and click on the + sign. However, ...

Enhancing web forms with Python and Selenium WebDriver: Implementing new input fields

Currently, I am utilizing the python3 unittest library in conjunction with selenium webdriver for my project. Despite having an existing question within my application, I am encountering a problem when attempting to add a new question. Rather than insertin ...

Navigating through lists and selecting elements - Automating with Selenium

Lately, I've been experimenting with automating the options page. With a variety of options, each having its own sub-options, manually declaring all elements by their xpath or CSS seems like a tedious task. Fortunately, I've come up with a reliab ...

Having trouble running the BasicReport class in C# code

I have been experimenting with test automation for ERP Dynamics AX 7 using Selenium. To record scenarios on Dynamics AX 365, I utilize the task recorder and generate reports using ExtentReports 2.41.0 by creating a class called BasicReport: using NUnit. ...