You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
WebDriver driver = null;
CallChromeWebDriver cd = new CallChromeWebDriver(driver,"Chrome");
driver = cd.getDriver();
driver.get("https://rahulshettyacademy.com/AutomationPractice/");
// reach the table
driver.findElement(By.xpath("//fieldset/table[@id='product']"));
//print number of rows
List<WebElement> rows = driver.findElements(By.xpath("//fieldset/table[@id='product']/tbody/tr"));
System.out.println("Number of rows: " +rows.size());
// print number of columns
System.out.println("Number of columns: "+ driver.findElements(By.xpath("//fieldset/table[@id='product']/tbody/tr/th")).size());
System.out.println("Contents of third column: " + driver.findElement(By.xpath("//fieldset/table[@id='product']/tbody/tr[3]")).getText());
cd.closeDriver();1 1
Realtive Locators
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import static org.openqa.selenium.support.locators.RelativeLocator.*;
public class RelativeLoc {
public static void main(String[] args) {
System.setProperty("webdriver.chrome.driver", "/Users/rahulshetty/Documents/chromedriver");
WebDriver driver=new ChromeDriver();
driver.get("https://rahulshettyacademy.com/angularpractice/");
WebElement nameEditBox =driver.findElement(By.cssSelector("[name='name']"));
System.out.println(driver.findElement(with(By.tagName("label")).above(nameEditBox)).getText());
WebElement dateofBirth = driver.findElement(By.cssSelector("[for='dateofBirth']"));
driver.findElement(with(By.tagName("input")).below(dateofBirth)).click();
WebElement iceCreamLabel =driver.findElement(By.xpath("//label[text()='Check me out if you Love IceCreams!']"));
driver.findElement(with(By.tagName("input")).toLeftOf(iceCreamLabel)).click();
WebElement rdb = driver.findElement(By.id("inlineRadio1"));
System.out.println(driver.findElement(with(By.tagName("label")).toRightOf(rdb)).getText());
}
}
Invoking multiple tabs/windows parallely - partial screenshot - saving the file to local - getting dimemsions of a webelement