Running the JavaScript function '.hover' using Selenium WebDriver

My goal is to utilize Selenium WebDriver to run some javascript code from a webpage. I have come across several helpful posts on executing javascript, but I often struggle when trying to call javascript from page objects (I am still learning the terminology and basics). Here is the javascript code on the page that I need to execute:

$j(".webGrid tr").hover(function () {
        $j(this).find("#imgEdit").css("visibility", "visible");
}

So far, my two closest attempts are as follows:

js.ExecuteScript("('.itemId').find('#imgEdit').css('visibility', 'visible')"); //1
js.ExecuteScript("(arguments[0]).find('#imgEdit').css('visibility', 'visible')", element); //2

I seem to be missing something in both cases. The first attempt gives me the error ".itemId".find is not a function, and the second one says arguments[0].find is not a function. It seems like 'find' might be the issue, but since it's part of the page's javascript file, there must be something I'm missing in my understanding.

Answer №1

Instead of directly interacting with elements on a webpage, consider using the ActionBuilder to hover over an element:


Actions builder = new Actions(driver);
builder.moveToElement(someElement);
builder.build().perform();

Alternatively, when trying to access innerHTML property using find in JavaScript, ensure that it is a function from a specific library and not a default browser feature. You can achieve this by executing a script like:


return ((IJavaScriptExecutor)webDriverInstance).ExecuteScript("return arguments[0].innerHTML", elementInstance).ToString();

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

Converting a Unix timestamp to a formatted date string in Firebase: A step-by-step guide

Is there a way to change a timestamp from 1333699439 to the format 2008-07-17T09:24:17? For now, I have been utilizing Firebase.ServerValue.TIMESTAMP for timestamps in Firebase. ...

After passing through JavaScript, my link becomes scrambled

As I'm coding in JavaScript for a website, I've come across a puzzling issue with this string. The troublesome line of code is: var app = "<a onclick='openApp('"+url+"')">"+icon+"</a>" Strangely, when executed, it pr ...

Add fresh material to the bottom of the page using Javascript

Hey there, I'm having a bit of trouble with my page where users can post their status. I want the new posts to appear at the bottom after the older posts when the user presses the button. Currently, Ajax is placing all new posts at the top of the old ...

Exploring the intricacies of AngularJS: Unraveling the

I’m currently diving into the world of Angular and grappling with retrieving JSON data. However, the concepts of $scope and $http are still a bit fuzzy for me. Can someone provide a clear explanation of what $scope and $http mean in this context? Below ...

Pressing on the identical object will shut down the menu, however, selecting a distinct item will

In my project, I have successfully created a side menu with icons. Upon clicking each icon, a menu slides out displaying relevant items. To achieve this functionality, I utilized the following code snippet: const handleCloseWhenOpen = menuOpen ? { onClick ...

I'm working on an Angular2 project and I'm looking for a way to concatenate all my JavaScript files that were created from TypeScript in Gulp and then include them in my index

How can I concatenate all JavaScript files generated from typescript in my Angular2 project with Gulp, and then add them to my index.html file? I am using Angular2, typescript, and gulp, but currently, I am not concatenating the javascript files it genera ...

Creating tables using ng-repeat in AngularJS and Bootstrap

Although I am new to Angular, I have been struggling with a problem for the past few days and can't seem to find a solution. I want to create a matrix of images (charts generated by angular-chart module) with 2 columns that will dynamically load a va ...

Implementing file change detection using view model in Angular

When using the input type file to open a file and trigger a function on change, you can do it like this: <input type="file" multiple="multiple" class="fileUpload" onchange="angular.element(this).scope().fileOpened(this)" /> The functi ...

Jsx Component fails to display following conditional evaluations

One issue I am facing is having two separate redux stores: items (Items Store) quotationItems (Quote Items). Whenever a product item is added to quotationItems, I want to display <RedButton title="Remove" />. If the quotationItems store i ...

Navigating to the bottom of a specific element by scrolling

I am currently working on enhancing a module within the application I'm developing. The goal is to automatically scroll the browser window to the bottom of an element when said element's height exceeds the height of the window. The functionality ...

Custom JavaScript code in Bootstrap Navbar Toggler results in closing the menu when a dropdown is clicked

As a newcomer to JavaScript, I am currently learning the language while working on a website. I have customized a template that I found online but am struggling with the JS code that I'm not very familiar with. Here's my issue: When using the na ...

passing arguments during deferred resolve() and when() operations

I am currently working on a flash card website and I need to determine the status of preloaded images once they have finished loading or if there was an error. After obtaining the status of each image, I will proceed with further actions. My code is inspi ...

Unable to utilize jQuery within the NetBeans IDE

Whenever I try to include a jQuery file in Netbeans like this: <script type="text/javascript" src="js/jquery-1.3.2.js"> my code doesn't seem to work. However, when I use the following method: <script type="text/javascript" src="http://ajax ...

Eliminate classes from radios that are not selected

Here is a snippet of the code I am working with: <ul id="id_priori"> <li> <label for="id_priori_0"> <input id="id_priori_0" name="priori" type="radio">Hola </label> </li> </ul> ...

Determine the y-coordinate of terrain in Three.js

I have acquired a Collada model of terrain and now wish to incorporate other models onto this terrain. To achieve this, I believe I need to retrieve the height coordinate (y) of the terrain based on specific x and z coordinates. Can someone please guide ...

An animation triggered by scrolling using the @keyframes rule

Is it possible to smoothly animate a variable font using @keyframes on scroll and have it complete the animation loop when the user stops scrolling, rather than snapping back to the starting position? I've managed to make the animation work, but it l ...

Having some trouble finding the input box element with Python/Selenium

I'm struggling to automate a task using Python. For some reason, I can't find the email input element with driver.find_element_by_. No matter what I try, I just can't seem to locate it. All I want is for Python to log in using Chromedriver. ...

Modify the CSS class of a customized component using a different component

Here is a small example illustrating my issue: https://github.com/lovefamilychildrenhappiness/AngularCustomComponentValidation The problem arises with a custom component that contains an input field. The formControl linked to this input field utilizes Val ...

The process of eliminating line breaks in javascript is not functioning as expected

I've been searching all over the place, experimenting with different methods, but I just can't seem to fix this issue.. var save_field = res[0]; var save_value = res[1]; save_value = save_value.replace(/\n/gm, '<br />'); con ...

Troubleshooting the AngularJS digest error within a hybrid application

My hybrid app is quite bulky, using angularjs 1.7 and angular 5.x simultaneously. I have integrated ngUpgrade module to manage both apps, but I encountered a problem when trying to navigate to a different route using href, which is causing the digest cyc ...