1. Edit Box:
Enter "Hello" word in edit box...
WebDriver driver = new InternetExplorerDriver();
WebElement element = driver.findElement(By.ID("txtbx"));
element.clear(); \\ Clear text box
element.sendKeys("Hello");
2. Drop Down :
Select "India" from country drop down.WebDriver driver = new InternetExplorerDriver();
WebElement element = driver.findElement(By.ID("dcountry"));
new Select(element).selectByVisibleText("India");
Also we can select by index.
new Select(element).selectByIndex(1);
or
new Select(element).selectByValue("India");
we can also deselect value from drop down using below code.
new Select(element).deselectByValue("India");
3. Radio button:
Select one of the type radio button.WebDriver driver = new InternetExplorerDriver();
WebElement element = driver.findElement(By.ID("type"));
element.click();
element.isSelected; // To check if radio button is clicked.
in case of multiple radio button and if we want to select one of the radio button then we can use findByElements to locate list of the radio button.
List <WebElement> radiolist = driver.findElements(By.ID("type"));
4. Checkbox :
Select one of the option checkbo.WebDriver driver = new InternetExplorerDriver();
WebElement element = driver.findElement(By.ID("option"));
element.click();
element.isSelected; // To check if check box is clicked.
in case of multiple checkboxes and if we want to select one of the checkbox then we can use findByElements to locate list of the checkbox.
List <WebElement> radiolist = driver.findElements(By.ID("option"));
5. WebButton:
To click on web Button or submit form details .WebDriver driver = new InternetExplorerDriver();
WebElement element = driver.findElement(By.ID("submit"));
element.click();
or
element.submit();
element.isEnabled(); // To check in button is enable or dissable..
element.isDisplayed(); // To check if button is visible ot not..
No comments:
Post a Comment