简体   繁体   中英

How to get control and pass the values in textbox in a webpage automatically

i wants to automatically load the url and get the control of signin button and pass the value to the text using c# in visual studio.i have tried using htmlagilitypack for getting the control and for passing the values in a textbox, i have used selenium webdriver. iam able to load the url and not able to get the control of signin button and not able to pass the value in textbox. could someone help me in this case i was stuck with past one week.i have attached the sample code i have tried.

using System;
using HtmlAgilityPack;
using System.IO;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Diagnostics;
using OpenQA.Selenium;
using OpenQA.Selenium.Edge;
using System.Threading;
using System.Threading.Tasks;   

namespace HtmlAgilityPackTest
{​​​​​
    class Program
    {​​​​​
        static void Main(string[] args)
        {​​​​​
            //string driver = "Email";
            string itext = "Sign In";
            //string email = "Email";
            //IWebDriver driver = new EdgeDriver();
            var uri = "https://developer.servicenow.com";
            var psi = new System.Diagnostics.ProcessStartInfo();
            psi.UseShellExecute = true;
            psi.FileName = uri;

            System.Diagnostics.Process.Start(psi);
            //Thread.Sleep(3000);
            var func = string.Format(@"document.getElementsByClass('dps-button-label').innerText = '{​​​​​0}​​​​​';",itext);

            //Thread.Sleep(3000);
                IWebDriver driver = new EdgeDriver();
                IWebElement element = driver.FindElement(By.Name("form-control input-box username-box"));

                element.SendKeys("xyz@gmail.com");  

your button is in lot shadowRoot: you have to do this function to click on signin button:

IJavaScriptExecutor js = (IJavaScriptExecutor)driver;

var query = "return document.querySelector('dps-app').shadowRoot"
query += ".querySelector('dps-navigation-header').shadowRoot"
query += ".querySelector('dps-login').shadowRoot"
query += ".querySelector('dps-button')"
js.ExecuteScript(query).click()

before executing this code, wait 3 or 5 sec to be sure the page html is loaded completely

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM