0% found this document useful (0 votes)
18 views7 pages

Selenium Part 2 - Jaikishan

The document discusses various Selenium commands for handling iframes, closing browser windows, exception handling, and waiting for elements and alerts. It provides code examples for switching frames, closing windows with close() vs quit(), try/catch blocks, and implicitly waiting for elements.

Uploaded by

Suresh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
18 views7 pages

Selenium Part 2 - Jaikishan

The document discusses various Selenium commands for handling iframes, closing browser windows, exception handling, and waiting for elements and alerts. It provides code examples for switching frames, closing windows with close() vs quit(), try/catch blocks, and implicitly waiting for elements.

Uploaded by

Suresh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 7

Selenium Commands

with Details

Part - 2

By : Jaikishan Mohanty
#5) Handling iframes
● Select iframe by id -- driver.switchTo().frame(“ID of the frame“);
● Locating iframe using tagName --
driver.switchTo().frame(driver.findElements(By.tagName(“iframe”).get(0));
● Locating iframe using the index: -- driver.switchTo().frame(0);
● Locating by Name of iframe -- driver.switchTo().frame(“name of the
frame”);

● Select Parent Window -- driver.switchTo().defaultContent(); •


#6) close() and quit() methods
● driver.close(); -- closes only a single window that is
being accessed by the WebDriver instance currently

● driver.quit(); -- closes all the windows that were


opened by the WebDriver instance
#7) Exception Handling
Exceptions are the conditions or situations that halt the program execution unexpectedly.

Reasons for such conditions can be:

● Errors introduced by the user


● Errors generated by the programmer
● Errors generated by physical resources

WebElement saveButton = driver.findElement(By.id("Save"));

try{ if(saveButton.isDisplayed()){

saveButton.click();} }

catch(NoSuchElementException e){

e.printStackTrace(); }
Other useful Commands :
● isEnabled() -- to Check Whether the Element is Enabled Or Disabled in the Selenium
WebDriver.

boolean textBox = driver.findElement(By.xpath("//input[@name='textbox1']")).isEnabled();

● pageLoadTimeout(time,unit) -- to set the time for a page to load.


driver.manage().timeouts().pageLoadTimeout(500, SECONDS);

● implicitlyWait() -- to set a wait time before searching and locating a web element.

driver.manage().timeouts().implicitlyWait(1000, TimeUnit.SECONDS);.
Other useful Commands :
● until() and visibilityOfElementLocated() -- until() from WebdriverWait
and visibilityOfElementLocated() from ExpectedConditions to wait explicitly till an element is
visible in the webpage.

WebDriverWait wait = new WebDriverWait(driver, 10);

WebElement element = wait.until(ExpectedConditions.visibilityOfElementLocated (By.xpath("//input[@id=’name’]")));

● untill() and alertIsPresent() -- untill() from WebdriverWait and alertIsPresent() from


ExpectedConditions to wait explicitly till an alert appears.

WebDriverWait wait = new WebDriverWait(driver, 10);

WebElement element = wait.until(ExpectedConditions.alertIsPresent() );


Share with all your Friends.👫
“Whatever you want to achieve in life, Help others to achieve that!!! “

Video Link: Selenium Command Part 2

Testing Jobs: https://t.me/TestingJobsAndInterview

All PDF file: https://t.me/Mohanty_Academy

THANK YOU
Jaikishan Mohanty

You might also like