0% found this document useful (0 votes)
5 views

Select Frames

Uploaded by

Ajay Pole
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)
5 views

Select Frames

Uploaded by

Ajay Pole
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/ 6

Select class

• Select class is an inbuilt class in Selenium


• In order to achieve methods available inside select
class we have to create an object for select class
first
• Import select class from Selenium.support.UI
• By using the select class we can handle
dropdowns.

Select s=new Select(dropdown);


How select values from the dropdown
s.selectByIndex();
s.selectByValue();
s.selectByVisibleText();
How to deselect the options from the dropdown
s.deSelectByIndex();
s.deSelectByValue();
s.deSelectByVisibleText();
s.deSelectAll();
• To check the dropdown is single select or multi
select we have a method called isMultiple() and
it’s return type is Boolean.

• s.isMultiple();
If it is multiple select dropdown returns True if not
False.
• To get all the options from drop down we have
method called getOptions()

s.getOptions();
• Inorder to get the selected options we have a
method called getAllSelectedOptions();
S. getAllSelectedOptions();

Script for selecting values:


package WebelementsHandling;
import java.time.Duration;
import java.util.List;
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.support.ui.Select;
public class Dropdown {
public static void main(String[] args) throws
InterruptedException
{
WebDriver driver = new ChromeDriver();
driver.manage().window().maximize();
driver.get("https://www.amazon.com/");
driver.manage().timeouts().implicitlyWait(Duration.ofS
econds(10));
WebElement dropdown =
driver.findElement(By.id("searchDropdownBox"));
Select s = new Select(dropdown);
s.selectByIndex(7);
Thread.sleep(3000);
s.selectByValue("search-alias=deals-intl-ship");
Thread.sleep(3000);
s.selectByVisibleText("Digital Music");
Thread.sleep(3000);
// s.deselectByIndex(1);
// Thread.sleep(3000);
// s.deselectByValue("199");
// Thread.sleep(3000);
// s.deselectByVisibleText("INR 300 - INR 399 ( 1 ) ");
List<WebElement> optn = s.getOptions();
System.out.println(optn.size());
for(WebElement allopt:optn)
{
System.out.println(allopt.getText());
}
Thread.sleep(3000);
driver.close();
}
}

Frames :
What is frame ?
Frames are the web pages which is inside another web
page
How do you get to know or identify frame ?
When we right click and inspect we can see an option
called frame, then we can understand that is a frame
How to handle the frame?
Handling frames through index:
• In order to handle frame first we have to shift our
control to frames with below statement.
• driver.switchTo().frame();
• frame()----> This method is available in
TargetLocator nested interface
• To Switch back our control from frame to normal
page we have to write below statement
• driver.switchTo().defaultContent();

Handling frames through Id or name:


• Id or name are the names of the attribute,
through which we will handle the frame.

driver.switchTo().frame("id or name
value of the element");
Handling frames through WebElement:
• Here we will fetch the address of frame and stores
in reference variable like ele.
• driver.switchTo().frame(ele);

You might also like