Clicking a link using Selenium WebDriver and JavaScript

I am currently utilizing Selenium-webdriver with C# to run tests on a website. However, I am encountering an issue where the Click() function is not working when I try to click on a link. The expected behavior is for a new window to open upon clicking the link. Upon inspecting the HTML structure, I noticed that there is a JavaScript action associated with the link.

Here is the relevant HTML code:

<span class="new_doc">
  <a style="cursor: pointer;" onclick="javascript:popwinnewproject('pc.aspx?page=docnew2tree&j=P2&grp=actv&t=');">
    <img title="new doc" src="http://local:8080/res/icon/new-doc.png"/>

Could anyone advise on the appropriate method to use in order to successfully click on the link and open the new window?

Answer №1

There are instances where I utilize JavaScript to trigger clicks:

IWebDriver driver = (IWebDriver)driver;
((IJavaScriptExecutor)executor).ExecuteScript("arguments[0].click();", element);

Here, the element being clicked is an IWebElement.

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

Ways to retrieve the React Router match object in mapStateToProps

Is there a way to access the react-router match object for its params from mapStateToProps or any other selector? I'd like to use these params to generate a value that will be passed down as props to a presentational component within the selector. The ...

Issue with Heroku: Unable to serve images through NodeJS Express server

I have an app deployed on Heroku that displays an image. app.js package.json package-lock.json public |__ image1.png |__ image2.png This is the code within app.js const express = require('express'); const app = express(); const path = re ...

Issues with the visibility of React Bootstrap components

I'm troubleshooting an issue with the carousel on my website. When I try to load the page, the carousel appears blank. To set up the carousel, I used npm to install react-bootstrap. The carousel code can be found at . Upon checking the web console, ...

Encountering "selenium.common.exceptions.NoSuchElementException" error while utilizing Chrome in Selenium

I'm attempting to play QWOP using Selenium on Chrome, but I am continuously encountering the following error message: selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element {"method":"id","selector":"wi ...

Utilizing vanilla JavaScript's addEventListener in a Vue component

It appears that vanilla event listeners do not function properly when targeting DOM elements within Vue components. Code Snippet <p id="test1">Hover over this (works)</p> <div id="app"> <p id="test2">Hover over this (not worki ...

Challenges associated with utilizing img src in JavaScript

I am facing a simple issue. I have carInfo data retrieved from a JSON file, but I am struggling to correctly parse the img source stored in the variable $imgsrc instead of treating it as a string called "$imgsrc". This data needs to be appended to my HTML ...

JavaScript: Dynamic animation of a DIV element based on conditions

I am looking to create an animation for a DIV layer when another div is clicked. However, I only want the animation to play if the DIV layer has not been animated yet. My initial thought was to check the height value, as I am animating the height of the d ...

Sending a JSON stringified JavaScript object to a server: A step-by-step guide

I am currently working with VB.Net and MVC 5. In my project, I have an object that I created using javaScript: var myEdits = { listOfIDs: [], listOfValues : [] }; My goal is to send this object to the controller an ...

Error encountered: Index 109 - The function $.ajax(...).success is not recognized as a valid function while working with jQuery in a Node

I'm just starting to learn about jquery and have been experimenting with ajax in my recent code. Below is the snippet of what I have implemented: $(function(){ $("#status").change(function(){ if($(this).is(':checked')) ...

Adjusting the alignment of Bootstrap navbar items upon clicking the toggle button

When I click the toggle button on a small screen, my navbar items appear below the search bar instead of aligning with the home and about elements. Below is an image depicting this issue: https://i.stack.imgur.com/4rabW.png Below is the HTML code structu ...

Establish a variable for the generated tree fragment

Currently, I am utilizing an xsl stylesheet to generate an xsl:fo document that includes an embedded SVG chart. However, I am facing difficulties when attempting to divide an array from the input into multiple smaller arrays stored in variables. This segme ...

Is it possible to simultaneously open multiple windows while utilizing selenium?

When initializing selenium, I aim to launch multiple separate windows that can operate independently: from lxml import etree import re from selenium import webdriver from selenium.webdriver.common.by import By # Selector from selenium.webdriver.common.key ...

Integrating objects into the <select> element through the combination of C#, JavaScript, and HTML connected to a SQL

Can someone assist me in resolving this issue? I am trying to populate an HTML element with database fields using C# and JavaScript, but so far my code is not producing any output. I have also attempted to include a button that calls the "loadGrp" function ...

Enhancing imported models in Three.js with antialiasing

When I import an OBJ model into my scene, it appears jagged and lacks smoothness. This is puzzling to me because when opened in Blender, the model looks perfectly smooth. On the other hand, the built-in geometries such as new THREE.SphereGeometry(4, 20, 2 ...

Storing images in a varbinary(max) column: best practices

When attempting to insert an image into SQL Server 2008, I encountered the following SQL exception: Implicit conversion from data type nvarchar to varbinary(max) is not allowed. Use the CONVERT function to run this query The datatype of the Image colum ...

Getting AJAX data in PHP: A comprehensive guide

As a student, I am working on creating a simple form for my website that will utilize ajax to save the submitted details to the database using PHP. I prefer not to use any external libraries like jQuery. Although I have successfully implemented the ajax "g ...

Knex is requesting the installation of sqlite3, but I am actually utilizing a MySQL database

While attempting to execute a query on my local MySQL database using knex, I encountered an issue where it prompted me to install the SQLite3 driver, even though my database is MySQL. To troubleshoot, I installed the SQLite3 driver to see if it would reso ...

Creating docked resizable expanders and grids using XAML in WPF: A step-by-step guide

I need help building a wpf application with two expanders, one on the left and one on the right, with a grid in between. The expanders should be able to resize themselves, automatically adjusting the size of the grid between them. See the image linked here ...

Ensure that the token remains current with each axios operation

I need to access an Express REST API that demands a valid json web token for certain routes. In order to include the token from localstorage every time I needed, I had to create an "Axios config file". My http.js file includes the code below: import Vue ...

Creating PropTypes from TypeScript

Currently in my React project, I am utilizing TypeScript along with PropTypes to ensure type checking and validation of props. It feels redundant to write types for both TypeScript and PropTypes, especially when defining components like ListingsList: inte ...