Experiencing difficulty with C#, WebView, and InvokeScriptAsync, unable to execute Click() on the Next link

Currently, I am extracting data from a webpage and have successfully implemented auto-login functionality. However, I am facing an issue with clicking the "Next" button on the page as it does not have an assigned ID. To locate the correct link, I must utilize XPath. The code snippet below effectively populates the fields.

string functionString = String.Format("document.getElementById('username').value = '{0}';", "usernamehere");
var result = string.Empty;
result = await webView1.InvokeScriptAsync("eval", new string[] { functionString });

The following XPath expression is what I need to identify the "Next" button.

"//a[contains(text(),'Next »')]"

Although I intended to use .Click() at the end, I am unable to get it to work properly. The syntax seems faulty, causing an HResult error.

String functionString = String.Format("document.evaluate(\"//a[contains(text(),'Next »')].Click();\"");
result = await webView1.InvokeScriptAsync("eval", new string[] { functionString });

Here is the relevant HTML code snippet from the page:

<span>
<a ng-class="{disabled: currentPage == pages_pagination.length-1}" href="" ng-click="nextPage(currentSearch)">Next »</a>
</span>

If you have any insights or suggestions on how I could approach this issue, please share them.

Answer №1

Refer to the following code snippet. Make sure to include all necessary parameters when using eval.

String functionString = String.Format("document.evaluate(\"//a[starts-with(text(),'Next')]\", document, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null).snapshotItem(0).click();")

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

The .complete callback in jQuery animate is triggered on five separate occasions

Having trouble identifying why the callback of animate is triggering multiple times. Can someone assist in finding my mistake? The code below scrolls a text block from top to bottom. The "step" of animate moves a custom scrollbar... currentText.stop().an ...

Looking for a new slider option to replace the traditional Conveyor belt slideshow?

I have successfully used the Conveyor belt slideshow script from http://www.dynamicdrive.com/dynamicindex14/leftrightslide.htm. Now, I am looking to find another script that works similar to this one. Does anyone have any recommendations for a tool that ...

Why does the SHA hash generated from an Angular application differ from that of an online tool when dealing with Unicode

When utilizing an Angular application to generate a hash for text containing the rupees symbol and unicode, it seems that the hash produced is consistent within the application but differs from online hash generation tools. Application ₹ - sha256(&apo ...

Step-by-step guide for integrating a Twig file in Symfony using Angular's ng-include feature

Seeking guidance in Angular, as a newcomer to the platform. I attempted to load a template within an ng-repeat loop like so, but encountered an error. I received the following error message: "Cross origin requests are only supported for protocol schemes ...

Storing a collection in a database using the MVC design pattern

Hello, I'm encountering an issue while attempting to store a list of email addresses in my database. Despite my efforts, I am unable to successfully save the list. Here is the List within the model: [Display(Name = "Mailing List")] public List<st ...

How can a service be injected in NestJs based on its interface?

I have a module named payment.module.ts with the following setup: @Module({ controllers: [PaymentController], }) export class PaymentModule {} In my payment.service.ts file, I want to utilize a service that adheres to an interface. Here is an example ...

What is the method for retrieving the current date based on abbreviated day names?

Within my web service, there is an API that provides information on the days when a shop is available for delivery. The API returns an object containing an ID (which is necessary to obtain hours based on the selected day) and the abbreviated day name (in I ...

Monitoring vuex mutations and actions within a component: A step-by-step guide

Is there a way to detect and react whenever events occur across the page, such as animations starting or finishing, requests firing or failing? I want a component to be able to respond to these occurrences. It's simple to watch a getter by importing ...

Patience is key as we wait for another observable to finish using await

Hi everyone, I am facing an issue in my Angular app where I have two methods getA and getB. I have added a third method getC which is dependent on the results from getB. Can someone guide me on how to properly wait for getB to complete before executing g ...

How does RequireJS identify modules that have been loaded prior to loading RequireJS?

Recently started working with the Require JS Framework. I am currently developing Angular directives to be used as reusable web components in a web app. Within my Angular modules and directives, I have specified dependencies with Require JS. If certain dep ...

Vue JS causing page to flash briefly before disappearing

I recently started exploring Vue and I'm working on creating a basic search function that takes a user input query and displays all matching users. To help me with this, I've been following a video tutorial for guidance. Despite not encounterin ...

The revealing module pattern in AngularJS is effective in most cases, but it can sometimes present challenges

Currently, I am engaged in a project that utilizes AngularJS. We are exploring the implementation of the revealing module pattern to ensure private functions are present in our controllers and services. While everything is functioning as anticipated, we ar ...

The Div element seems to have a mind of its own, refusing

Check out my code on this link: http://jsfiddle.net/Pd7nm/ I'm trying to make the sidebar stop scrolling with the page once it reaches a certain point, but it just won't cooperate. I've attempted various solutions, but none seem to be effec ...

Angular: Radio button groups are not responding correctly when populated within a loop using ng-repeat

My goal is to populate multiple sets of radio buttons in a loop by combining the group name and index to ensure each set is uniquely grouped. However, I am facing an issue where only the last group in the loop has a checked radio button, while all other gr ...

Ensure that the "Read more" button appears on the same line as the truncated text after a specified number of lines

I am working on getting the Read more feature to appear on the same line as the truncated text after a certain number of lines. Currently, it is showing up below the truncated text. <p style={{ overflow: 'hidden', display: '-webkit-box&ap ...

What is the best way to sketch a line stretching from the center of the page to the right edge?

Is it possible to create a line that extends from the center of the page to the right side using CSS, HTML, or JS? This line should be able to adjust for various screen resolutions. An example is shown in the accompanying image. ...

When the program is executed, immediately use .trigger('click')

There is a spelling game that features a grid filled with hidden words. The objective of the game is to spell out these words by clicking on the letters of the alphabet, aided by hints such as images and sounds. Players are given the word they need to spe ...

Encountering issues when attempting to insert information into PostgreSql utilizing AngularJs paired with a C# WebService backend

As a beginner in angularjs, I have set up the HTML file and linked it to the RegistrationController.js. Additionally, I have created the Registration.cs file for managing data retrieval and storage from a database. Despite not encountering any errors, I am ...

Encountering a node globby error when implementing multiple patterns

Currently, I am successfully using node glob for folder1 as shown below: glob('folder1/*.js'), function(err, files){ if (err) { console.log('Not able to get files from folder: ', err); } else { files.forEach(function (file) ...

Jade refusing to display JavaScript code

When it comes to calling my script.js file from inside jade, I seem to be encountering some trouble. Although JavaScript renders perfectly fine when inserted inline, for some reason the external js file is not being called properly. In my initial attempt, ...