Unable to locate and interact with a specific element within a dropdown menu while utilizing Protractor

I am currently facing an issue with selecting a checkbox from a dropdown in jq widgets. The code seems to work fine when the element is visible on the screen, but fails otherwise. I have tried various methods such as executeScript and scrollIntoView to bring the element into view for Protractor to detect it, but nothing seems to be working. I would appreciate any help or suggestions on how to resolve this problem.

// conf.js
exports.config = {
    directConnect: true,
    framework: 'jasmine',
    specs: ['jq.spec.js'],

    jasmineNodeOpts: {
        showColors: true,
        defaultTimeOutInterval: 30000000
    },
}

Here is my jq.spec.js:

describe('Testing jq widgets functionality', function() {

    it("should verify proper scrolling behavior",function() {
        browser.ignoreSynchronization = true;
        browser.get('http://www.jqwidgets.com/jquery-widgets-demo/demos/jqxdropdownlist/checkboxes.htm?arctic');
        browser.wait(protractor.ExpectedConditions.visibilityOf($('#dropdownlistContentjqxWidget')),500000,'dropdown did not display');
        $('#dropdownlistContentjqxWidget').click().then(function(){
            $('#listitem0innerListBoxjqxWidget>div').click();
            scrollIntoView(element(by.xpath("//span[text()='Francisco Chang']/parent::div/div")));
            element(by.xpath("//span[text()='Francisco Chang']/parent::div/div")).click();
            browser.sleep(10000);
        });
    });
});

var scrollIntoView = function(element){
    browser.executeScript(function(element) {
        element.scrollIntoView();
        }, element.getWebElement());
    });

};

//errors:

Failures:
1) Testing jq widgets functionality should verify proper scrolling behavior
  Message:
    Failed: No element found using locator: By(xpath, //span[text()='Francisco Chang']/parent::div/div)

Answer №1

If you're encountering issues with the scrollIntoView function in Jasmine, it might be beneficial to make some adjustments. The current setup seems to resolve everything into the control flow but returns void, causing the execution of scrollIntoView to start immediately and not wait for browser.executeScript to be added to the control flow. This can lead to clicking on an element before it has been properly scrolled into view. To ensure completeness, consider adding a JSDoc as shown below:

/**
 * Scroll to bring an element into view
 * @param {ElementFinder} element - the target element
 * @returns {webdriver.promise.Promise} - a promise from WebDriver
 */
var scrollIntoView = function(element) {
    return browser.executeScript(function(element) {
        element.scrollIntoView();
    }, element.getWebElement());
};

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

Retrieving parameters from the URL in Angular

I'm facing an issue with my app. I am currently using a factory to manage data for two controllers. When I click on a link that redirects me to another view with a specific URL, I want to reuse the last tag in the URL by slicing it like this: window. ...

An HTML document may display a segment of a URL

Is there a way to display part of a URL in an HTML document, so that if the URL changes, the corresponding content in the body also updates? For instance, www.example.com/?key=i - Is it possible for this link to be dynamically displayed within the body o ...

Verify the Element and proceed to the subsequent tag

I have a list with various elements, each containing its own delete button. If I want to delete a specific element (such as Test 1 or Test 2), I first need to confirm the element and then proceed with deleting it. <div class="html-replace-container"> ...

Parameter of ExpectedConditions in Selenium

During my experience with writing Selenium tests, I've observed that the methods in the ExpectedConditions class vary in terms of parameters. Some methods only require a By parameter, some only require a WebElement, and others have overloaded versions ...

Why am I unable to utilize methods in Vue.js?

Hey everyone, I'm currently working on a website that includes a home page and a specific 'Brazil' component. To switch between the two, I am using vue router. Within the Brazil component, there is a calculator feature that should take a gra ...

Exploring the power of Angular's ng-repeat to generate hierarchical lists

I am looking to display a structured list of layers and sublayers by looping through an object using ng-repeat. var lyrslist = [ { layername: "Base Maps", layertype: "layer" }, { layername: "Open Street Map", layertype: "sublayer" },    { layer ...

Is it possible to customize the deep elements of ExpansionPanelSummary using styled-components in React?

After digging into the documentation and examples on how to customize Material UI styling with styled-components, I successfully applied styling to the root and "deeper elements" within an ExpansionPanel and ExpansionPanelDetails. However, when attempting ...

What is the best way to import a TypeScript file in index.js?

I've recently developed an application using the react-express-starter template. I have a "server" directory where the backend is created by nodejs, containing an index.js file: const express = require('express'); const app = express(); c ...

Tips for including a JWT token as a query parameter in NEXT js?

const UserJwt = (props) => { const { jwt } = props; const [jwtToken, setJwtToken] = useState(null); useEffect(() => { if (jwt) { setAuthToken(jwt); setJwtToken(jwt); } }, [jwt]); return <MobilePurchaseScreen {...pro ...

Tips for sending multiple JSON objects using the ajax() method

As of now, I have successfully implemented a $.getJSON() call to fetch a JSON string from a specific URL. Here is the simplified code that is currently functioning well: $.getJSON("myURL",function(data){ var receivedJSON = data; }); The retrieved JSO ...

What is the best way to display JSON data in a Listview control?

What is the best way to display JSON data in a list format? Currently, I am able to retrieve JSON data and display it in an alert dialog. The JSON data looks like this: [{"_id":"5449f20d88da65bb79a006e1","name":"name3","phone":"888888","service":"service ...

Element could not be found inside the pop-up dialog

I have been attempting to find those buttons displayed here: https://i.stack.imgur.com/5M1qd.png Here is the HTML for them: https://i.stack.imgur.com/238no.png I've experimented with different methods, but unfortunately, nothing has succeeded. ...

Having trouble with Google Maps Places API autocomplete feature; it's not functioning properly

My goal is to integrate the Google Maps Places API with a search box. To test jQuery autocomplete, I managed to make it work using this simple example: function bindAutocomplete() { var locationSearch = $("input#Location"); locationSearch.autocom ...

Styling tables within HTML emails for Gmail and then utilizing PHPMailer to send the emails

I've been racking my brain over this for hours with no luck! Objective: Implementing inline styles for table, td, th, p elements in an HTML email intended for Gmail using PHPMailer. Challenge: Inline styles not being rendered HTML Snippet: <sec ...

Exploring the process of web scraping from dynamic websites using C#

I am attempting to extract data from using HtmlAgilityPack. The website is dynamic in nature, displaying content after the page has fully loaded. Currently, my code retrieves the HTML of the loading bar using this method, but encounters a TargetInvocation ...

Error: Failed to parse the given color specification

My chrome extension is showing an error message: Unchecked runtime.lastError: The color specification could not be parsed. This error seems to be in the popup.html: 1 -> <! DOCTYPE html> line. Can anyone explain what this means and how to fix it? ...

Transform basic text into nested JSON structure with JavaScript

There is a plain string in my possession which contains various conditions. const optionString = '{2109} AND ({2370} OR {1701} OR {2702}) AND {1234} AND ({2245} OR {2339})'; The goal is to transform this string into an object structured as foll ...

Update the displayed locations on Google Maps by fetching and displaying marker data

I am able to retrieve and display information from my MySQL table, but I need assistance with refreshing this data every 5 seconds using my current code. The data being shown is not extensive, just about 5 or 8 markers at a time. Below is the code I curren ...

Error: Unable to interpret the URL provided in /api/posts/1

When working on my next.js 13 app, I encountered an issue while trying to fetch individual blog data from a local MySQL database. In the src/blog/[id]/page.js file, I have the following component: const BlogPost = async ({ params }) => { const data ...

Leveraging a collection of URLs with Python Selenium

I have a text document containing a list of URLs called all_urls.txt. Each URL in the file is listed on its own line. I am looking to utilize Selenium with Python in order to extract specific data from each of these URLs. Currently, my approach involves pr ...