1) Identify Background Color Using Selenium
Webdriver
To find the color of background, Get the Element through Id, Xpath, or CSS Locators
To find the color of background, Get the Element through Id, Xpath, or CSS Locators
Then follow the below:
WebElement element = driver.findElement(By.id("color");
System.out.println(element.getAttribute("background-color"));
WebElement element = driver.findElement(By.id("color");
System.out.println(element.getAttribute("background-color"));
2) Click a button random times Using Selenium
Webdriver
int clickTimes = (int)Math.random()*100
for (int i = 0; i < clickTimes; i++)
button.click()
for (int i = 0; i < clickTimes; i++)
button.click()
3) Click on Javascript popup "OK" and "Cancel"
buttons within the Popup
For clicking the OK button - driver.switch.alert.accept()
For clicking on cancel button - driver.switch.alert.dismiss()
For clicking on cancel button - driver.switch.alert.dismiss()
4) Get the text values of an element(Here Head and Paragraph Elements) through Loop
public void testtext(){
webDriver().switchTo().defaultContent();
webDriver().switchTo().frame("retentionschedule");
webDriver().switchTo().frame("main");
List<WebElement> pageSubElement1 =
webDriver().findElements(By.className("guztext1"));
//List<String> heads=new ArrayList<String>();
for (int i=0; i<pageSubElement1.size(); i++){
String element= pageSubElement1.get(i).getText();
System.out.println(element);
}
List<WebElement> pageSubElement2 =
webDriver().findElements(By.className("guzhead1"));
for (int i=0; i<pageSubElement2.size(); i++){
String elements=pageSubElement2.get(i).getText();
System.out.println(elements);
}
}
4) Handle JavaScript Pop up
driver.switchTo().alert().dismiss();
driver.switchTo().alert().accept();
No comments:
Post a Comment