How to use Selenium Webdriver in C #, how to select a text field for writing, and then write in it?

Have a script to go to the site. Now I want to log in and go to the next screen. I can’t find the code on how to go into the text field "username:" and then "password:".

+6
source share
4 answers

You need to tell us the HTML page, but with a password text field:

<input type="password" id="passwordTextBox">

I would find it using Selenium WebDriver, for example:

IWebDriver firefoxDriver = new FirefoxDriver();
IWebElement passwordTextBox = firefoxDriver.FindElement(By.Id("passwordTextBox"));

Then I will write into it like this:

passwordTextBox.Clear();
passwordTextBox.SendKeys("password");

I would look at the Selenium Web Driver documentation and ask any questions after you read all of this:

http://seleniumhq.org/docs/03_webdriver.html

+19
//Textbox  id is "username"
IWebDriver driver = new ChromeDriver();    
string url = "https://www.google.com";
IWebElement textBox;
driver.Navigate().GoToUrl(url);
textBox = driver.FindElement(By.Name("username"));
textBox.SendKeys("Test text");
0
driver.FindElement(selectBy(controlToFind, search)).Click();

.

  • driver= your selena web driver
  • SelectBy(controlToFind)= this is your control, xpath code, CSS selector, or class.
  • .Click()= It is an action that needs to be done, you can use the .click(), .SendKeys(), wait()...
0
source

Enter a value in the Username and Password text box. Try below

driver.FindElement(By.Id("\\UserName Text Box ID\\").SendKeys("UserName Text");

driver.FindElement(By.Id("\\Password Text box ID\\").SendKeys("Password Text");
-2
source

Source: https://habr.com/ru/post/1538953/


All Articles