Posts

Showing posts from March, 2021

How to handle frame window in selenium?

package webElementMethods; 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 HandleFrameGetAttributes { public static void main(String[] args) { System.setProperty("webdriver.chrome.driver", "D:\\Software\\Testing-Tools\\Selenium\\WebDriver\\Drivers\\IEChromeFirefox\\19092018\\chromedriver.exe"); WebDriver driver = new ChromeDriver(); driver.manage().window().maximize(); driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS); driver.get("https://jqueryui.com/draggable/"); WebElement frameBox = driver.findElement(By.xpath("//*[@id=\"content\"]/iframe")); driver.switchTo().frame(frameBox); System.out.println(driver.findElement(By.id("draggable")).getAttribute("style")); driver.switchTo().defaultContent(...

How to work with mouse hover menu in selenium?

package wdProgram; 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 org.openqa.selenium.interactions.Actions; public class HandleMouseOverEvent { public static void main(String[] args) { System.setProperty("webdriver.chrome.driver", "D:\\Software\\Testing-Tools\\Selenium\\WebDriver\\Drivers\\IEChromeFirefox\\19092018\\chromedriver.exe"); WebDriver driver = new ChromeDriver(); driver.manage().window().maximize(); driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS); driver.get("https://www.amway.com/"); driver.findElement(By.xpath("//html/body/div[2]/table/tbody/tr[1]/td[2]/table/tbody/tr/td[3]/ul/li/a")).click(); WebElement mainMenu = driver.findElement(By.xpath("//*[@id=\"menu\"]/li[4]/a")); WebElement subMenu = driv...

How to handle alert window?

  package wdProgram; import java.util.concurrent.TimeUnit; import org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org.openqa.selenium.chrome.ChromeDriver; public class HandleAlertWindow { public static void main(String[] args) { System.setProperty("webdriver.chrome.driver", "D:\\Software\\Testing-Tools\\Selenium\\WebDriver\\Drivers\\IEChromeFirefox\\19092018\\chromedriver.exe"); WebDriver driver = new ChromeDriver(); driver.manage().window().maximize(); driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS); driver.get("http://localhost/uth/gadgetsgallery/catalog"); driver.findElement(By.linkText("create an account")).click(); driver.findElement(By.id("tdb1")).click(); String alertText = driver.switchTo().alert().getText(); System.out.println(alertText); driver.switchTo().alert().accept();   //Clicks on OK button //driver.switchTo().alert...

How to extract all the links in selenium?

  package wdProgram; 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 org.testng.annotations.BeforeTest; import org.testng.annotations.Test; public class ExtractAllLinks { WebDriver driver; @BeforeTest public void openBrowser() { System.setProperty("webdriver.chrome.driver", "D:\\Software\\Testing-Tools\\Selenium\\WebDriver\\Drivers\\IEChromeFirefox\\19092018\\chromedriver.exe"); driver = new ChromeDriver(); driver.manage().window().maximize(); driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS); } @Test public void testExtractAllLinks() { driver.get("http://localhost/uth/gadgetsgallery/catalog"); WebElement catBox = driver.findElement(By.xpath("//*[@id=\"left_sidebar\"]/div[1]/div[2]"));...

How to manage cookie of website in selenium?

package wdProgram; import java.util.Set; import java.util.concurrent.TimeUnit; import org.openqa.selenium.By; import org.openqa.selenium.Cookie; import org.openqa.selenium.WebDriver; import org.openqa.selenium.chrome.ChromeDriver; import org.testng.annotations.BeforeTest; import org.testng.annotations.Test; public class CookieMakeMyTrip { WebDriver driver; @BeforeTest public void openBrowser() { System.setProperty("webdriver.chrome.driver", "D:\\Software\\Testing-Tools\\Selenium\\WebDriver\\Drivers\\IEChromeFirefox\\19092018\\chromedriver.exe"); driver = new ChromeDriver(); driver.manage().window().maximize(); driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS); } @Test public void testHandleCookie() throws InterruptedException { driver.get("http://localhost/uth/gadgetsgallery/catalog"); System.out.println("---------------Cookies before Login---------------"); S...

How to split the value & convert string to float in selenium?

  package TestCaseA; import java.text.DecimalFormat; import java.util.List; import org.openqa.selenium.By; import org.openqa.selenium.WebElement; import org.openqa.selenium.interactions.Actions; import org.openqa.selenium.support.ui.ExpectedConditions; import org.openqa.selenium.support.ui.WebDriverWait; import org.testng.annotations.Test; import com.aventstack.extentreports.ExtentTest; import com.aventstack.extentreports.Status; import BaseClass.BaseInit; import MyMethods.SignIn; import Utility.ScreenShot; public class Cart extends BaseInit { @Test public static void cart() throws InterruptedException { reports.attachReporter(reporters); ExtentTest Test = reports.createTest("Cart"); driver.get(sitedata.getProperty("url")); try { SignIn.login("uss.jignesh@gmail.com", "123456"); Thread.sleep(10000); WebDriverWait wait = new WebDriverWait(driver, 10); // wait.until(ExpectedConditions.invisibilityOfElement...