In this article, we are going to learn, how the WebDriver access the forms.
As we know that the forms contains different elements such as Radio Button,Checkbox,Text/Input Box,Drop-Down List, Links etc. We are going learn, how the WebDriver access all these elements in this article.
Links:
Links are accessed by using the click() method.
Example:Consider the following link found in Yahoo home page.
We can access the link using "LinkText()" or "PartialLinkText()" with the combination of "click()" method. We can use either of the following 2 lines to access the "SIGN IN" link marked above.
PartialLinkText() method:
driver.FindElement(By.PartialLinkText("SIGN")).Click();
LinkText() method:
driver.FindElement(By.LinkText("SIGN IN")).Click();
Radio Button:
Radio Button can also be toggled using click() method.
Example:Consider the following Radio buttons.
We can toggle anyone of the above shown radio button using click method.The following code snippet toggle the Red radiobutton option.
driver.FindElement(By.CssSelector("input['value=Red']")).Click();
Input Box:
Input Box refers either of the following 2 types of fileds.
Entering values in Input Box:
We can enter values in the Input Box by using SendKeys() method.
Code:
driver.FindElement(By.Name("Username")).SendKeys("test");
The above code will type the text "test" in Username field.
Deleting the values from Input Box:
We can delete values from the Input Box by using clear() method.
Code:
driver.FindElement(By.Name("Username")).clear();
The above code will clear the text "test" from Username field.
As we know that the forms contains different elements such as Radio Button,Checkbox,Text/Input Box,Drop-Down List, Links etc. We are going learn, how the WebDriver access all these elements in this article.
Links:
Links are accessed by using the click() method.
Example:Consider the following link found in Yahoo home page.
We can access the link using "LinkText()" or "PartialLinkText()" with the combination of "click()" method. We can use either of the following 2 lines to access the "SIGN IN" link marked above.
PartialLinkText() method:
driver.FindElement(By.PartialLinkText("SIGN")).Click();
LinkText() method:
driver.FindElement(By.LinkText("SIGN IN")).Click();
Radio Button:
Radio Button can also be toggled using click() method.
Example:Consider the following Radio buttons.
We can toggle anyone of the above shown radio button using click method.The following code snippet toggle the Red radiobutton option.
driver.FindElement(By.CssSelector("input['value=Red']")).Click();
Input Box:
Input Box refers either of the following 2 types of fileds.
- Text Fields: Text fields accepts the values typed by the user and shows as it is.[Ex:Username field in login screen.]
- Password fields: Password fields also accepts the values typed by the user and displays in encrypted format to maintain the security as the password is a sensitive from user's point of view.
Entering values in Input Box:
We can enter values in the Input Box by using SendKeys() method.
Code:
driver.FindElement(By.Name("Username")).SendKeys("test");
The above code will type the text "test" in Username field.
Deleting the values from Input Box:
We can delete values from the Input Box by using clear() method.
Code:
driver.FindElement(By.Name("Username")).clear();
The above code will clear the text "test" from Username field.
0 comments:
Post a Comment