How to get controls and pass the values in TextBox in a webpage automatically using c#

Mary Jessy 1 Reputation point
2021-11-06T10:45:31.573+00:00

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.

var uri = "https://developer.servicenow.com";

        var psi = new System.Diagnostics.ProcessStartInfo();

        psi.UseShellExecute = true;

        psi.FileName = uri;

        System.Diagnostics.Process.Start(psi);

var func = string.Format(@"document.getElementsByClass('dps-button-label').innerText = '{​​​​​0}​​​​​';",itext);

IWebDriver driver = new EdgeDriver();

            IWebElement element = driver.FindElement(By.Name("form-control input-box username-box"));

            element.SendKeys("anon@user ");  
C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
10,204 questions
{count} votes

4 answers

Sort by: Most helpful
  1. P a u l 10,406 Reputation points
    2021-11-06T13:21:11.97+00:00

    It may not be related to your issue but it looks like you're getting the textbox by it's name but passing a class name. Does it work if you change this?:

    IWebElement element = driver.FindElement(By.Name("form-control input-box username-box"));
    

    To:

    IWebElement element = driver.FindElement(By.Id("username"));
    
    0 comments No comments

  2. Mary Jessy 1 Reputation point
    2021-11-07T05:51:33.79+00:00

    Thanks, but first i needs to get the control of sign in button in servicenow login page, for that iam using this below command
    IWebElement ele = driver.FindElement(By.Name("dps-button-label"));
    or
    var func = string.Format(@"document.getElementsByClass('dps-button-label').innerText = '{​​​​​0}​​​​​';",itext);

    but it doesn't click the sign in button in servicenow login page.can i get an ans for this?

    0 comments No comments

  3. Lydia Bernadat Mary S 1 Reputation point
    2021-11-07T09:22:07.343+00:00

    Thanks much, able to get the signin control and pass the email id value to the text and not able to pass the value for password field and click on signin button atlast i tried this code but it shows (element not interactable) exception, i have attached the code that i have tried, could someone help me in this case. (IWebElement pas1 = driver.FindElement(By.Id("password")); pas1.SendKeys("xxxxx"); IWebElement ele3 = driver.FindElement(By.Id("submitButton")); ele3.Click();)

    0 comments No comments

  4. Lydia Bernadat Mary S 1 Reputation point
    2021-11-09T08:06:00.31+00:00

    Hi,
    I got the answer.Thanks

    0 comments No comments