Navigating through a webpage in search of a specific element with Robot Framework

I've been utilizing robot framework on a java/javascript page, attempting to scroll to a locator for verification of its text value. Although I found a solution in this QA that matches my issue, it throws an exception when executed.

Unable to scroll down the web page using the Robot Framework

Here is the locator I'm trying to scroll to:

${CLAIMS}    xpath=//*[@id="generalAndIncidents:relatedAlertsPanel:idPreviousClaimsList"]

This is the keyword I'm using for scrolling (it takes one argument for the locator variable):

Scroll To Element
[Arguments]    ${scroll_to_element}
Sleep    1s
Execute JavaScript    window.document.evaluate("${scroll_to_element}", document.body, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue.scrollIntoView(true);
Sleep    1s

However, upon execution, I am encountering the following exception:

20:36:17.376    INFO    Executing JavaScript:
window.document.evaluate("xpath=//*[@id="generalAndIncidents:relatedAlertsPanel:idPreviousClaimsList"]", document.body, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue.scrollIntoView(true);
Without any arguments.  
20:36:17.758    FAIL    JavascriptException: Message: javascript error: missing ) after argument list
  (Session info: MicrosoftEdge=86.0.622.69)

I have also referred to this page for guidance on the javascript code snippet:

https://developer.mozilla.org/en-US/docs/Web/API/Document/evaluate

If you could provide me with some advice on how to start debugging, or if there are any issues in what I am doing, I would greatly appreciate it. Could it be related to missing escapes?

Thank you very much!

Update#1: Is this possibly linked to the namespace resolver?

Update#2:

Scroll To Element
    [Arguments]    ${scroll_to_element}
    ${x} =    Get Horizontal Position    ${scroll_to_element}
    ${y} =    Get Vertical Position      ${scroll_to_element}
    Execute Javascript    window.scrollTo(${x}, ${y})

Scroll Loop Click
    [Arguments]    ${locator}
    FOR    ${index}    IN RANGE    1    10
        Sleep    0.5s
        ${isElementVisible} =    Run Keyword and Return Status    Click Element    ${locator}
        Run Keyword If    '${isElementVisible}'!='True'    Wait Until Keyword Succeeds    6s    2s    Scroll To Element    ${locator}
        Log    ${isElementVisible}
        Exit For Loop If    '${isElementVisible}'=='True'
    END
    Wait Until Element is Visible    ${locator}

Answer №1

Here is a code snippet that I found on Stackoverflow and have successfully used:

Scroll To Element
    [Arguments]  ${element}
    ${x}=        Get Horizontal Position  ${element}
    ${y}=        Get Vertical Position    ${element}
    Execute Javascript  window.scrollTo(${x}, ${y})

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

React- Input value disappears after submission

Implementing validation for email-based input has been a bit of a challenge for me. I have managed to set up the debounce function for onChange event handling, but encountered a strange issue. The problem arises when the user submits an invalid string bef ...

What is the recommended way to initiate the first server-side external API query in Nuxt 3 and where should it be done?

I have a question regarding the process of developing web applications in Nuxt 3 using the composition API. I am working on an application that requires user location-dependent content. To achieve this, I need to determine the user's IP address using ...

Achieving function calling from controller to view with ng-click

I'm facing an issue with two buttons on my page. <div class="btn-group" ng-init="showData = 1"> <button ng-model="showData" type="button" ng-class='{"btn btn-primary": showData == 1, "btn btn-white": showData != 1}' ng-click= ...

Error: Unexpected TypeError occurred stating that 'map' cannot be read from undefined, although the map method is not being used in the code

I have recently developed an Ethereum application for conducting transactions using React and the ethers module. Below, you can see a snippet of my code, specifically focusing on the function sendTransactions: import {ethers} from 'ethers'; impor ...

Upgrade your yarn version in order to rectify any yarn audit errors

Currently, there doesn't seem to be a yarn audit --fix command available. Thus, I am exploring different approaches to resolve the errors detected in my yarn audit. While executing a yarn upgrade, some of the errors were successfully addressed, but a ...

Unable to sort array within a computed property in Vue.JS

Currently, I am working on enhancing my skills in Vue.js and have encountered an issue with sorting arrays in Vue.js. Despite using the sort(a-b) method for ascending order (least alphabet/value first), the array remains unchanged. Even with a function ins ...

What does the client perceive or not perceive? Node.js, JavaScript, MySQL

For a university project, I am tasked with creating a web application that is compatible with both desktop browsers and mobile devices. The technologies I will be using include HTML, CSS, JavaScript, Node.js, and MySQL. I have recently familiarized myself ...

Issue with ExpressJS Regex not correctly matching a path

I'm currently struggling with a simple regex that is supposed to match words consisting of letters (0-5) only, but for some reason it's not working as expected. Can anyone help me figure out the correct expression and how to implement it in Expre ...

Stop individuals from submitting numerous forms without refreshing the page

I have successfully implemented a PHP/AJAX form that displays a message when the form is submitted or encounters an error. However, the page does not refresh upon form submission, making it susceptible to multiple submissions with just a double click (or m ...

Prevent the page from automatically refreshing when the back button is pressed

How can I prevent a web page from refreshing when users navigate back to it? My web page displays unique information with each refresh, but I want it to maintain its previous state when users return to it. Is there a way to achieve this? If so, how can i ...

What is the appropriate content-type to use when sending AJAX POST data?

Having an issue sending base64 image data using ajax post. I suspect the problem lies with the Content-Type value, as I have tried using application/json, text/json, and image/jpeg without success. Javascript function sendFormData(fD) { var urls = fD ...

Hiding or revealing the coupon field on the Magento cart page

I am currently using Magento 1.7 and I'm in need of a solution or some guidance to address the following problem: I am looking to hide the coupon field on the cart page and instead have a link that reads "Have a coupon? Click here to use it". When ...

What is the best method for removing table rows with a specific class?

I have an html table with several rows, and for some of these rows the class someClass is applied. My question is: How can I delete the rows that have a specific class? <table> <tr class="someClass"> ...</tr> <tr class="someClass"> ...

Looking to showcase the outcome of the Procedure invocation when I made the call?

{ "isSuccessful": true, "resultSet": [ { "name": "pradeep", "password": 123, "timestamp": "2014-04-08T12:58:45.000Z" }, { "name": "dileep", "password": 1234, "timestamp": "2014-04-08T13:00:52.000Z" } ] } I have ...

How to display content in separate divs using jQuery hover functionality

I'm in the process of creating my online portfolio by using bootstrap and jquery. I have a series of images arranged side by side with each other, and I want to make the description for each image appear when that specific image is hovered over. Each ...

What is the best way to calculate the total sum of values in textboxes sharing the same class that were dynamically created through ajax calls

Looking for assistance to calculate the sum of values in textboxes generated dynamically through AJAX. The textboxes have the class name adminhours and are created via AJAX. The total sum should be displayed in another textbox when there is a change event ...

Adding an attribute to the last item of an Angular / NGX Bootstrap component

I am working with a dynamic list that utilizes NGX Bootstrap Dropdowns to showcase 4 sets of dropdown lists. However, the Dropdowns in the final list are getting obscured off-page. Thankfully, NGX Bootstrap offers a solution in the form of a dropUp option ...

The addEventListener function seems to encounter issues in IE11

There is a javascript function below that uploads the selected file and updates the grid. It works perfectly in Firefox, but there seems to be an issue with IE11. The "ESignature/Registration" function within the addEventListener does not seem to execute ...

Utilize Google Maps Location API to automatically complete addresses and display selected results

Previously, my code was functioning properly. It provided location autocomplete and displayed the result on a small map in a div. However, I encountered an issue which is demonstrated in this JSFiddle. After selecting a location, the map div appeared comp ...

Guide on verifying jQuery selector using jasmine

We are currently tasked with testing a function that determines the top position of an element. Specifically, we need to evaluate the top position of an element with the ID 'test'. function findTopPosition(){ var targetElement = $('#tes ...