Sunday, April 26, 2020

How to Handle Dynamic Table

package com.seleniumtest;

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;

public class WebTableTest {

public static void main(String[] args) throws InterruptedException {
System.setProperty("webdriver.chrome.driver","C:\\Users\\admin\\Desktop\\Selenium_software\\chromedriver.exe\\");
WebDriver driver=new ChromeDriver();
driver.get("https://www.makemytrip.com/");
driver.manage().window().maximize();
driver.manage().timeouts().implicitlyWait(10,TimeUnit.SECONDS);
driver.findElement(By.xpath("//input[@id='departure']/preceding::span[1]")).click();
Thread.sleep(1000);
List<WebElement> listtable=driver.findElements(By.xpath("//div[@class='DayPicker-NavBar']/following::div[2]//p"));
for(int i=0;i<listtable.size();i++) {
String str=listtable.get(i).getText();
System.out.println("strList...."+str);
if(str.equals("28")) {
listtable.get(i).click();
break;

}
}
System.out.println("Test case is passed");
}}
======================================================================
Example 2:- 
package com.seleniumtest;

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;

public class WebTableTest1 {

public static void main(String[] args) {
System.setProperty("webdriver.chrome.driver","C:\\Users\\admin\\Desktop\\Selenium_software\\chromedriver.exe\\");
WebDriver driver=new ChromeDriver();
driver.get("https://www.redbus.in/");
driver.manage().window().maximize();
driver.manage().timeouts().implicitlyWait(10,TimeUnit.SECONDS);
driver.findElement(By.xpath("//span[@id='togglebtn']/following::div[4]/span")).click();
List<WebElement> listOfTable=driver.findElements(By.xpath("//div[@id='rb-calendar_onward_cal']/table/tbody//td"));
for(int i=0;i<listOfTable.size();i++) {
String strLit=listOfTable.get(i).getText();
System.out.println("strLit..."+ strLit);
if(strLit.equals("28")) {
listOfTable.get(i).click();
break;
}
}
System.out.println("Test case passed");
driver.close();

}

}
========================================================================
Add caption

No comments:

Post a Comment

Q) How To Find Duplicate Characters In A String In Java?

Step1:- Creating a HashMap containing char as key and it's occurrences as value. Step2:- Converting given string to char array. Step3:- ...