Q)How to handle Dynamic table and Create Re-usable method and add in framework.
package com.seleniumpractice;
import java.util.List;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import com.businesshelper.Helper;
public class Dyamictable extends Helper{
public static void main(String[] args) {
/*
System.setProperty("webdriver.chrome.driver","D:\\driver1016\\chromedriver.exe");
WebDriver driver=new ChromeDriver();
driver.get("https://www.redbus.in/");
driver.manage().window().maximize();
driver.manage().timeouts().implicitlyWait(10,TimeUnit.SECONDS);
*/
Helper.launchApp();
driver.findElement(By.xpath("//button[contains(text(),'Search Buses')]/preceding::span[1]")).click();
Helper.selectDate(driver,"10");
/*
List<WebElement> list=driver.findElements(By.xpath("//table[@class='rb-monthTable first last']/tbody//td"));
for(int i=0;i<list.size();i++){
String strlist=list.get(i).getText();
System.out.println("strlist-->" + strlist);
if(strlist.equals("10")){
list.get(i).click();
break;
}
*/
}
}
=========================================================================
package com.businesshelper;
import java.util.List;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.interactions.Actions;
public class Helper {
public static WebDriver driver;
public static String driverPath="D:\\driver1016\\chromedriver.exe";
public static String url="https://www.redbus.in/";
public static List<WebElement> listofCheckbox;
public static void launchApp(){
System.setProperty("webdriver.chrome.driver",driverPath);
driver=new ChromeDriver();
driver.get(url);
driver.manage().window().maximize();
}
public static boolean verifyisSeleted(WebElement ele){
boolean status= ele.isSelected();
if(status){
System.out.println("CheckBox is selected");
}
else{
System.out.println("CheckBox is not selected");
}
return status;
}
/*
public static void multipleCheckbox(){
listofCheckbox=driver.findElements(By.xpath("//input[@type='checkbox']"));
for(WebElement listele:listofCheckbox){
listele.click();
}
}
*/
public static boolean isDisplayedRadiobtn(WebElement ele){
boolean eleisisplaye=ele.isDisplayed();
if(eleisisplaye){
System.out.println("Radio Button is Displayed ");
}
else{
System.out.println("Radio Button is not Displayed ");
}
return eleisisplaye;
}
public static boolean isEnabledRadioButton(WebElement ele){
boolean eleisEnabled=ele.isEnabled();
if(eleisEnabled){
System.out.println("Radio Button is Enabled ");
}
else{
System.out.println("Radio Button is not Enabled");
}
return eleisEnabled;
}
public static void ClickWithActions(WebElement ele){
Actions act=new Actions(driver);
act.moveToElement(ele).click().perform();
}
public static void selectDate(WebDriver driver,String str){
List<WebElement> list=driver.findElements(By.xpath("//table[@class='rb-monthTable first last']/tbody//td"));
for(int i=0;i<list.size();i++){
String strlist=list.get(i).getText();
if(strlist.equals("10")){
list.get(i).click();
break;
}
}
}
}
====================================================================
Q) How to handle Dynamic table in Selenium
No comments:
Post a Comment