question

MaryJessy-0488 avatar image
0 Votes"
MaryJessy-0488 asked LydiaBernadatMaryS-5429 answered

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

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 ");  
dotnet-csharp
· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

@MaryJessy-0488, We noted that htmlagilitypack is a 3rd party product, I recommend that you could ask the question in StackOverflow.


0 Votes 0 ·
Paul-5034 avatar image
0 Votes"
Paul-5034 answered

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"));
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

MaryJessy-0488 avatar image
0 Votes"
MaryJessy-0488 answered

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?

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

LydiaBernadatMaryS-5429 avatar image
0 Votes"
LydiaBernadatMaryS-5429 answered LydiaBernadatMaryS-5429 published

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();)

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

LydiaBernadatMaryS-5429 avatar image
0 Votes"
LydiaBernadatMaryS-5429 answered

Hi,
I got the answer.Thanks

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.