Automated Testing with Robot Framework: Utilizing Javascript to Click on a Button

Inspecting the web page

<span jsslot="">
<button class="LkLjZd ScJHi IfEcue HPiPcc KXT7c" jsaction="click:yTqzwd" jsname="HxVe9c" autofocus="">Click Here</button>
</span>

I am trying to interact with the element by using Execute Javascript. Here is my attempt

Execute JavaScript      document.evaluate("//button[contains(text(),'Click Here')]",document.body,null,9,null).singleNodeValue.click()

Although the test passes, there is no visible action on the web page. It remains unchanged. Can anyone assist?


I have figured out the solution. Since there are multiple iframes, I need to select the correct iframe before running the command like so

Select Frame      xpath=//*[@id="obj"]/div[5]/iframe
Execute JavaScript      document.evaluate("//button[contains(text(),'Click Here')]",document.body,null,9,null).singleNodeValue.click()

Answer №1

Utilizing Execute JavaScript for Clicking Elements in Robot Framework

If you're looking for a solution to clicking elements in Robot Framework, the answer can be found in the above link. Here is one of the solutions shared:

${element_xpath}=       Replace String      ${element_xpath}        \"  \\\"
Execute JavaScript  document.evaluate("${element_xpath}", document, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null).snapshotItem(0).click();

Multiple solutions are available in the provided link, so give them a try as well.

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

Java/Selenium error - Encountered java.lang.NullPointerException

Every time I run my test, I keep encountering a "java.lang.NullPointerException". How can I resolve this issue? I've tried looking at other resources but still facing some difficulties. Any assistance in solving this problem would be greatly appreciat ...

Unable to add files to my JavaScript file

I recently integrated React into an existing project, following the guidelines outlined here: https://reactjs.org/docs/add-react-to-a-website.html. Now, I'm facing an issue where I am unable to import any files (both .js and .css) into my main compone ...

Applying these sorting functions to my specific scenario

Hello everyone, I hope you can help me out with this issue. I have been struggling for hours trying to sort my array of objects in JavaScript based on a specific property, but I just can't seem to get it right. I have referred to some of the top post ...

Tips for locating an element within a DIV using Selenium Automation:

I'm struggling to locate and extract the value of a specific div element. Despite trying both Xpath and cssSelector methods, I keep encountering the following error in the Eclipse console: org.openqa.selenium.NoSuchElementException: no such element ...

Showcasing or concealing.JSON data depending on the selected item in a React and MaterialUI application

Looking to enhance the user experience, I am developing a dynamic FAQ section sourced from a JSON file containing an array of objects with 'Question' and 'Answer'. https://i.stack.imgur.com/mljpm.png The functionality is such that click ...

Tips for locating next tags in Selenium relevant to a specific tag

Need help with clicking on the 'Recommended' input tag for a 'Samsung' label? Check out the HTML code snippet below: <div class="card-wrapper"> <a class="card-focus has-shadow" href="/app/72292"> <div class="card-contain ...

Is there a way to prevent the conversion of .json/.webmanifest URLs into base64 strings?

I've been grappling with an issue for quite some time now. In my VSCode vite-react-typescript project, I have a link in the index.html file pointing to a webmanifest, which is essentially a json file with a different extension. After building my app, ...

Is the variable empty outside of the subscribe block after it's been assigned?

Why is a variable assigned inside subscribe empty outside subscribe? I understand that subscribe is asynchronous, but I'm not sure how to use await to render this variable. Can someone please help me and provide an explanation? I am attempting to retr ...

Is there a way to incorporate the information from PHP files into the output produced by JavaScript?

I am currently working on a JavaScript script that scrapes data and displays the result on the screen successfully. However, I now face a challenge in wrapping this output with pre and post content from PHP files for formatting purposes. Here is an overvi ...

Executing tests across various browsers using Selenium Grid and JUnit

Currently, I am working on configuring automated selenium testing but I am unsure about how to run tests in multiple browsers. After researching online, I was able to set up selenium grid with various browsers and successfully execute my tests. Now, I am ...

Drawing images on a Canvas using specified coordinates: A step-by-step guide

https://i.stack.imgur.com/YkibI.jpg I've been trying to position images on specific coordinates, but I'm having trouble getting the shapes and angles right. Currently, only the top left corner is matching correctly. var _width, _height; var im ...

When updating the HTML content, JavaScript is outputting the code as text instead of running it

I am encountering an issue with adding the body content of a JSON file, which contains HTML code, to my existing HTML. Instead of executing the code, it appears as text within paragraph or header elements. I have searched through various discussions but ha ...

Adjust the scroll position when the height of a div is modified

Imagine we have a large div A with a height value and below it are other divs B, C, and more. If the user is viewing divs B or C, and A reduces its height by half, the scrolling position will remain the same. However, divs B and C will move up by that amo ...

Changing marker colors dynamically in Google Maps with NextJS

I'm using the @googlemaps/js-api-loader package to load a map in my nextJS app. I have a list of locations that I want to plot on the map, and I also want these locations disabled on the left side of the page. When hovering over one of the locations ...

Having difficulty fetching the xpath from Science Magazine as it results in an empty list with no elements

Currently, I am working on a page that can be accessed through doi.org using the article code: 10.1126/science.aaa1442 I am attempting to extract the content within the address tag by utilizing the following xpath expression: //li[@class='aff'] ...

What is the process for creating a custom Javascript function that can seamlessly integrate with other Javascript libraries?

Is there a way to create a method that can be linked or chained to jQuery methods and other library methods? For example, consider the following code snippet: var Calculator = function(start) { var that = this; this.add = function(x) { start = start ...

Unlock hidden content with a single click using jQuery's click event

I have a question that seems simple, but I can't quite get the syntax right. My issue is with a group of stacked images. When I click on an image, I want it to move to the front and display the correct description above it. Currently, clicking on the ...

Creating a button that integrates an image within a single div element

Currently, I understand the code: $('#leftDev').css("background-image", "url(img/1.png) "); will set the entire background of my leftDiv to display "1.png". However, I would like to position this image as a regular picture within the div and no ...

Node.js offers a simple and efficient way to retrieve screen resolution. By using

I am trying to retrieve the screen resolution using node.js, but the code snippets provided are not working as expected. var w = screen.width; var h = screen.height; The following code also did not work for me: var w = window.screen.width; var h = windo ...

What is the ideal way to utilize Vue within the framework of multiple pages?

When using the default Vue CLI setup, Vue is loaded from the index.html page. To work with Vue and dynamic content on the page, everything is typically handled in the App.vue file. But what if you want to make significant layout changes to the page? How d ...