0% found this document useful (0 votes)
8 views2 pages

Selenium

The document provides an overview of various wait strategies in Selenium WebDriver, including implicit, explicit, and fluent waits. It details the use of the Actions class for performing user interactions such as hover, drag and drop, double-click, and right-click. Additionally, it covers handling multiple windows, alerts, iframes, and taking screenshots in a Selenium testing environment.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views2 pages

Selenium

The document provides an overview of various wait strategies in Selenium WebDriver, including implicit, explicit, and fluent waits. It details the use of the Actions class for performing user interactions such as hover, drag and drop, double-click, and right-click. Additionally, it covers handling multiple windows, alerts, iframes, and taking screenshots in a Selenium testing environment.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

driver.manage().timeouts().implicitlyWait(Duration.

ofseconds(9)); // implicit wait

WebDriverWait wait = new WebDriverWait(driver,30);


wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("..."))); //
explicit wait

Fluentwait wait = new Fluentwait(driver); // fluent wait


wait.withTimeOut(10,TimeUnit.second);
wait.pollingEvery(5,TimeUnit.Second);
wait.ignoring(NoSuchElementException.class)

Action Class
--------------

Actions action = new Actions(driver);


WebElement element = driver.findElement(By.linkText("hithere"));

action.moveToElement(element).build().perform(); - hover over


-------------------------------------------------------------------------
Actions action = new Actions(driver) // Drag and drop

action.dragAndDrop(element1,element2).build().perform();

Actions action = new Actions(driver);

Action dragandDrop = action.clickAndHold(from element)


.moveToElement(to Element)
.release(to element)
.build();

dragandDrop.perform();

--------------------------------------------------------------------------------

Actions action = new Actions(driver)

action.doubleClick(element).perform(); // double click

--------------------------------------------------------------------------------
Right click

Actions action = new Actions(driver);


action.contextClick(element).perform();

--------------------------------------------------------------------------------

Handling multiple window:


driver.get(k.com);
driver.findElement(By.id(user)).click();
string Mainwindow = driver.getWindowHandle();
Set<String> childwindow = driver.getWindowHandles();
Iterator<String> I1 = childwindow.iterator();
while(I1.hasNext()){
String nextwindow = I1.next();
if(!MainWindow=nextwindow){
driver.switchTo().window(nextwindow).getTitle();

-----------------------------------------------------------------------
Alerts

driver.switchTo().alert().dismiss(); // to click the cancel button

driver.switchTo().alert().accept(); // to click on the ‘OK’ button of the alert.

driver.switchTo().alert().getText(); // This method is used to capture the alert


message.

driver.switchTo().alert().sendKeys("HI");// This method is used to send data to the


alert box.

-----------------------------------------------------------------------------------
-----------
iframe/frame

List<WebElement> ele = driver.findElements(By.tagName("iframe"));


for(webElement w:ele)
driver.switchTo().frame(w);
System.out.println(w.getText());
-----------------------------------------------------------------------------------
-------
ScreenShot

TakesScreenShot sc = ((TakesScreenShot)WebDriver);
File src = sc.getScreenShotAs(outputType.file);

You might also like