Handling Frames, Multiple Browsers, Mouse hover in Selenium

preview_player
Показать описание
Handling Web Elements in Selenium WebDriver using Element Locators and WebDriver API Commands or Methods. Handling Frames, Switch from Top window to a Frame, Switch from a Frame to Top Window, Handling Mouse hover, and Working with multiple Browsers.
Рекомендации по теме
Комментарии
Автор

Class Notes:
Handling Frames, Multiple Browsers, Mouse hover in Selenium

In Handling Elements in Selenium Part-1

i) Handling Browser
ii) Handling Edit Box
iii) Handling Text Area, Error Message, Popup Window
iv) Handling Button

In Handling Elements in Part-2

v) Handling Images (General Image, Image Button, Image Link)
vi) Handling Link
vii) Handling Radio Button
viii) Handling Drop down box
ix) Handling Check box
x) Handling Web Table

Handling Elements in Part-3

xi) Handling Frames
xii) Handling Mouse hover
xiii) Handling Multiple browsers

xi) Handling Frames

> HTML Frames are used to divide the Browser window into multiple sections, where each section
can load a separate HTML document.

> Frames are sections of Web page displayed on Top window

> Whenever we access the page then focus on the top window.

Operating Elements in Frames

1) Manual Testing:

You can directly operate elements in any frame of the Page.

2) Test Automation / Automated Testing:

Switch from Top window to particular frame then operate elements.

Launch Web Page (It has 3 frames)

i) Click 3rd link in 3rd frame
ii) Click 2nd Link in 1st Frame
iii) Click 1st Link in 2nd frame

Test Automation:

a) Launch the web page
b) Switch to 3rd frame and operate the element
c) Switch to Top window
d) Switch to 1st frame and operate the element
e) Switch to Top window
f) Switch to 2nd frame and operate the element

Switch from Top window to a frame is done in two ways

i) Using Frame Index

Syntax:

driver.switchTo().frame(int index);

Example:

WebDriver driver = new FirefoxDriver();
driver.switchTo().frame(2);


ii) Using Frame Name

Syntax:

Name);

WebDriver driver = new FirefoxDriver();



From a frame to Top window

Syntax:



Example:

> Launch the Web Page
> Switch to 3rd Frame
> Operate an Element
> Back to Top Window
> Switch to 1st Frame
> Operate an Element

Frame Name

WebDriver driver = new FirefoxDriver();

//Switch from Top window to 3rd Frame using Frame name


Thread.sleep(3000);
//Back to Top window

Thread.sleep(3000);
//Switch from Top window to 1st Frame using Frame name



Frame Index

WebDriver driver = new FirefoxDriver();

//Switch from Top window to 3rd Frame using Frame name
driver.switchTo().frame(2);

Thread.sleep(3000);
//Back to Top window

Thread.sleep(3000);
//Switch from Top window to 1st Frame using Frame name
driver.switchTo().frame(0);


Thread.sleep(3000);
driver.navigate().back();
driver.switchTo().frame(1);


12) Handling Mouse hover

WebDriver driver = new FirefoxDriver();

//Create Actions Instance by Passing the driver reference
Actions builder = new Actions(driver);

WebElement menu = YOUR CAR"));




xiii) Handling Multiple Browsers

WebDriver driver = new FirefoxDriver();

String parent = driver.getWindowHandle();
//System.out.println(parent);

In")).click();

Set <String> Browsers = driver.getWindowHandles();


for (String i : Browsers){
if (! i.equals(parent)){
driver.switchTo().window(i);

}
}



Example:

Launch the Web Page
> Click Sign In Link (It opens new window)
> Enter some value into Login Username Edit box in 1st browser
> Enter some value into Enter Your details edit box in 2nd browser

WebDriver driver = new FirefoxDriver();

In")).click();


Thread.sleep(3000);
String Browser1 = driver.getWindowHandle();

Set <String> Browsers = driver.getWindowHandles();

for (String windowHandle: Browsers){
if

}
}
Thread.sleep(3000);

word")).sendKeys("abcd123");
}
}

gcreddy