Selenium WebDriver Interview Questions
1) Give a detailed introduction virtually Selenium WebDriver?
Selenium 1 (Selenium IDE + selenium RC + Selenium Grid)
Selenium 2 (Selenium IDE + Selenium RC + Selenium WebDriver + Selenium Grid)
Note: Selenium WebDriver merged alongside Selenium 1 as well as called every bit Selenium 2.
• It is a most of import tool inwards Selenium suite.
• It is has programming interface allows us to practice as well as execute Test cases against dissimilar browsers (ex: Firefox, IE, Google Chrome etc...)
• WebDriver supports diverse programming languages(Java, .Net, PHP, Perl, Python as well as Ruby) to elevate Test cases.
• WebDriver supports diverse operating environments (MS Windows, UNIX as well as Macintosh etc...) to practice as well as execute Test cases.
• WebDriver supports Data Driven testing, Cross browser testing.
• Webdriver is faster than other tools inwards Selenium suite.
• WebDriver supports Parallel assay execution alongside the aid of TestNG.
• WebDriver doesn't convey IDE, alone Programming interface.
• WebDriver doesn't convey built inwards Result reporting facility, it provides summary only.
(* alongside the aid of TestNG nosotros tin generate HTML assay reports.)
• No object Repository inwards selenium WebDriver (This limitation is for entire Suite), therefore no centralized maintenance of Objects).
• Using Element locators, Webdriver methods as well as Java programming features nosotros tin createand execute Test cases.
2) How to gear upward Selenium WebDriver Environment?
• Download as well as install Java (JDK) software - to elevate assay cases using Java programming features.
• Set Path surround variable- to access Java from whatsoever directory.
• Download Eclipe IDE as well as extract
• Download WebDriver Java Language binding as well as add together Webdriver jounce files (in Eclipse)
• Install Firebug as well as FirePath plug ins for Mozilla Firefox browser to inspect Elements.
Note: For Internet Explorer as well as Google chrome, no require to install whatsoever plug ins, They convey built inwards Developer tools.
Note 2: Element locators as well as WebDriver methods are mutual for all browsers, browser driver alone varies from i browser to another.
Note 3: Firefox driver is default driver inwards Webdriver, For IE as well as Chrome nosotros require to download drivers.
Download Selenium WebDriver Java binding from www.seleniumhq.org website as well as extract.
Navigation for adding Webdriver jounce files inwards Eclipse.
Create Java projection inwards Eclipse
> Select src as well as correct click
> Build path
> Configure Build Path
> direct Libraries tab
> Click "Add External JARs
> Browser path of the WebDriver jars
> Add
3) How to practice Test cases using Selenium WebDriver?
• Using Element locators, WebDriver methods as well as Java programming features nosotros tin practice Test cases.
• Element locators for recognizing objects/elements.
• WebDriver Methods are used perform operatopns on Elements or objects.
• Java Programming for enhancting Test cases.
4) What are the Testing frameworks back upward Selenium WebDriver alongside Java?
JUnit
TestNG
We tin job either JUnit or TestNG testing framework alongside Java as well as Webdriver
5) What are the Element Locators that Selenium WebDriver supports to recognize Elements?
Selenium Webdriver supports eight Element locators to recognize Objects/Elements.
i) id
ii) name
iii) className
iv) tagName
v) linkText
vi) partialLinkText
vii) cssSelector
viii) xpath
Note: We tin job whatsoever i unique locator to recognize the Object/Element.
6) What is Cross Browser Testing?
Testing spider web applications using multiple browsers, Cross browser testing involves checking compatibility of the application.
7) How to comport Cross Browser Testing using WebDriver?
• Using Browser Drivers nosotros tin comport Cross browser testing.
• For Mozilla Firefox, nosotros no require to download the browser driver.
• For IE as well as Chrome etc... browsers download the browser drivers as well as laid path.
Create Browser Driver Object for Mozilla Firefox:
WebDriver driver = novel FirefoxDriver();
Create Browser Driver Object for Internet Explorer:
System.setProperty("webdriver.ie.driver", "E:/IEDriverServer.exe");
WebDriver driver = novel InternetExplorerDriver();
Create Browser Driver Object for Google Chrome:
System.setProperty("webdriver.chrome.driver", "E:/chromedriver.exe");
WebDriver driver = novel ChromeDriver();
8) What are the of import operations on Browser object?
Operation: Open URL
WebDriver code: driver.get("http:/google.com");
Operation: Return Browser Title
WebDriver code: String s = driver.getTitle();
Operation: Return Current URL
WebDriver code: String s = driver.getCurrentUrl();
Operation: Close focused Browser
WebDriver code: driver.close
Operation: Close all Browsers that opened past times WebDriver
WebDriver code: driver.quit
9) What are the Elements/Objects inwards Web Applications?
Link
Button
Image, Image Link, Image Button
Text box
Edit Box
Text Area
Check box
Radio Button
Drop downward box
List box
Combo box
Web tabular array /HTML table
Frame
Etc...
10) Write a Test illustration using Selenium WebDriver?
Manual Test Case:
Test Case Name: Admin Login
Steps:
i) Launch the Browser as well as navigate to www.gcrit/build3/admin/
ii) Enter user name
iii) Enter Password
iv) Click Login button
Verification point:
--------------------
Check the existance of "Logoff" link, if exists as well as then exceed otherwise fail
Selenium Test Case:
WebDriver driver = novel FirefoxDriver();
driver.get("http://www.gcrit.com/build3/admin/");
driver.findElement(By.name("username")).sendKeys("admin");
driver.findElement(By.name("password")).sendKeys("admin@123");
driver.findElement(By.id("tdb1")).click();
if (driver.findElement(By.linkText("Logoff")).isDisplayed()){
System.out.println("Login Successful");
}
else {
System.out.println("Login Failed");
}
11) How to comport Batch Testing using WebDriver?
Using TestNG Annotations nosotros tin grouping Test cases as well as execute serial of Test cases.
12) How to stimulate Link element?
Operation: Click Link
WebDriver code: driver.findElement(By.linkText("Gmail")).click();
Operation: Check the link existance
WebDriver code:
boolean a = driver.findElement(By.xpath(".//*[@id='gbw']/div/div/div[1]/div[1]/a")).isDisplayed();
System.out.println(a); //true
Operation: Check the link enabled status
WebDriver code:
boolean b = driver.findElement(By.xpath(".//*[@id='gbw']/div/div/div[1]/div[1]/a")).isEnabled();
System.out.println(b); //true
Operation: Return the Link Name
WebDriver code:
String c = driver.findElement(By.xpath(".//*[@id='gbw']/div/div/div[1]/div[1]/a")).getText();
System.out.println(c); //Gmail
13) How to stimulate Button element?
Important operations on Buttons:
Enabled status
Display status
Click
Return rear of the Button
type of the object
Example:
public static void main(String[] args) {
WebDriver driver = novel FirefoxDriver();
driver.get("https://gmail.com");
WebElement push = driver.findElement(By.id("next"));
boolean a = button.isDisplayed();
boolean b = button.isEnabled();
button.getAttribute("name");
button.getAttribute("type");
button.click();
System.out.println(a);
System.out.println(b);
}
14) How to stimulate Edit box element?
Important Operations on Edit box:
Enter a Value,
Clear the Value,
Check enabled status,
Check edit box existence,
Get the value etc...
----------------------------
Example:
public static void main(String[] args) {
WebDriver driver = novel FirefoxDriver();
driver.get("https://gmail.com");
//Enter a Value
driver.findElement(By.id("Email")).sendKeys("ABCD123");
//Return the Value
String value = driver.findElement(By.id("Email")).getAttribute("name");
//Return Type of the Object
String value2 = driver.findElement(By.id("Email")).getAttribute("type");
//Return display status
boolean a = driver.findElement(By.id("Email")).isDisplayed();
//Return Enabled status
boolean b = driver.findElement(By.id("Email")).isEnabled();
System.out.println(value);
System.out.println(value2);
System.out.println(a);
System.out.println(b);
// Clear the Value
driver.findElement(By.id("Email")).clear();
}
}
15) How to stimulate Images?
Three types of Image elements inwards Web Environment
1) General Image (No functionality)
2) Image Button (Submits)
3) Image Link (Redirects to unopen to other page/location)
Example:
public static void main(String[] args) {
WebDriver driver = novel FirefoxDriver();
driver.get("https://google.com");
String Title = driver.findElement(By.id("hplogo")).getAttribute("Title");
System.out.println(Title);
driver.navigate().to("http://newtours.demoaut.com/");
driver.findElement(By.name("login")).click();
driver.navigate().to("http://www.seleniumhq.org/");
driver.findElement(By.xpath(".//*[@id='choice']/tbody/tr/td[2]/center/a/img")).click();
}
16) How to stimulate Radio Button element?
Operations on Radio Button
i) Select Radio Button
ii) Verify if the Radio Button is Displayed or not?
iii) Verify if the Radio Button is enabled or not?
iv) Verify if the Radio Button is Selected or not?
---------------------
Example:
public static void main(String[] args) {
WebDriver driver = novel FirefoxDriver();
driver.get("http://www.gcrit.com/build3/create_account.php?osCsid=boh81f11tmud1134jnp5ne7r20");
boolean a = driver.findElement(By.xpath(".//*[@id='bodyContent']/form/div/div[2]/table/tbody/tr[1]/td[2]/input[1]")).isDisplayed();
System.out.println(a); //true
boolean b = driver.findElement(By.xpath(".//*[@id='bodyContent']/form/div/div[2]/table/tbody/tr[1]/td[2]/input[1]")).isEnabled();
System.out.println(b); //true
boolean c = driver.findElement(By.xpath(".//*[@id='bodyContent']/form/div/div[2]/table/tbody/tr[1]/td[2]/input[1]")).isSelected();
System.out.println(c); //false
driver.findElement(By.xpath(".//*[@id='bodyContent']/form/div/div[2]/table/tbody/tr[1]/td[2]/input[1]")).click();
boolean d = driver.findElement(By.xpath(".//*[@id='bodyContent']/form/div/div[2]/table/tbody/tr[1]/td[2]/input[1]")).isSelected();
System.out.println(d); //true
driver.findElement(By.xpath(".//*[@id='bodyContent']/form/div/div[2]/table/tbody/tr[1]/td[2]/input[1]")).clear();
}
17) How to stimulate Check box element?
Operations on Check box
i) Check if the cheque box is displayed or not?
ii) Check if the cheque box is enabled or not?
iii) Check if the cheque box is Selected or not?
iv) Select the Check box
v) Unselect the Check box
Example:
public static void main(String[] args) {
WebDriver driver = novel FirefoxDriver();
driver.get("file:///E:/HTMLExamples/MultipleCheckbox.html");
boolean display = driver.findElement(By.xpath("html/body/input[2]")).isDisplayed();
System.out.println("Displayed Status: " + display);
boolean enabled = driver.findElement(By.xpath("html/body/input[2]")).isEnabled();
System.out.println("Enabled Status: " + enabled);
boolean cheque = driver.findElement(By.xpath("html/body/input[2]")).isSelected();
System.out.println("Check Status: " + check);
driver.findElement(By.xpath("html/body/input[2]")).click();
boolean check2 = driver.findElement(By.xpath("html/body/input[2]")).isSelected();
System.out.println("Check Status: " + check2);
driver.findElement(By.xpath("html/body/input[2]")).click();
boolean check3 = driver.findElement(By.xpath("html/body/input[2]")).isSelected();
System.out.println("Check Status: " + check3);
}
18) How to stimulate Frames?
• HTML frames are used to dissever our Browser window into multiple sections,
where each department tin charge a separate html document.
• Frames are sections of Web page displayed on tiptop window.
• Whenever nosotros access the page as well as then focus is on the tiptop window.
Switch to a frame is done inwards 2 ways:--------------------------------------
i) Using frame index
Syntax:
driver.switchTo.frame(int index);
ii) Using frame name
Syntax:
driver.switchTo.frame(String name);
Example:
//Using Frame index
public static void main(String[] args) {
WebDriver driver = novel FirefoxDriver();
driver.get("http://seleniumhq.github.io/selenium/docs/api/java/index.html");
driver.switchTo().frame(0);
driver.findElement(By.xpath("html/body/div[2]/ul/li[1]/a")).click();
}
-------------------------------
//Using Frame name
public static void main(String[] args) {
WebDriver driver = novel FirefoxDriver();
driver.get("http://seleniumhq.github.io/selenium/docs/api/java/index.html");
driver.switchTo().frame("packageListFrame");
driver.findElement(By.xpath("html/body/div[2]/ul/li[1]/a")).click();
}
---------------------------------
Switch from a frame to Top window:
driver.switchTo().defaultContent();
Example:
public static void main(String[] args) {
WebDriver driver = novel FirefoxDriver();
driver.get("http://seleniumhq.github.io/selenium/docs/api/java/index.html");
//Switch from Top window to third frame
driver.switchTo().frame(2);
driver.findElement(By.xpath("html/body/div[3]/table/tbody[2]/tr[1]/td[1]/a")).click();
//Switch from third frame to Top window
driver.switchTo().defaultContent();
//Switch from Top window to 1st frame
driver.switchTo().frame(0);
driver.findElement(By.xpath("html/body/div[2]/ul/li[1]/a")).click();
}
}
19) How to stimulate Web Table?
Important Operations on Web Table:
Get prison theatre mobile telephone value
Rows Count
Cells Count
Example:
public static void main(String[] args) {
WebDriver driver = novel FirefoxDriver();
driver.get("file:///E:/HTMLExamples/htmlTable.html");
String s = driver.findElement(By.xpath(".//*[@id='students']/tbody/tr[2]/td[2]")).getText();
System.out.println(s);
WebElement htmlTable = driver.findElement(By.id("students"));
List <WebElement> rows = htmlTable.findElements(By.tagName("tr"));
int i = rows.size();
System.out.println(i);
List <WebElement> cells = htmlTable.findElements(By.tagName("td"));
int j = cells.size();
System.out.println(j);
}
20) How to stimulate Multiple Browsers?
We tin Handle Multiple Browsers using Browser window handle.
21) How to stimulate duplicate elements/objects?
We tin Handle duplicate objects/elements using index, index starts from 0 to ix as well as Top left of the spider web page to Bottom right.
--------------------------------------------
Selenium Interview Questions-1
Selenium Interview Questions-2
Java for Selenium Interview Questions
Selenium WebDriver Questions
Selenium IDE Questions
TestNG Interview Questions
Sumber http://www.gcreddy.com/
1) Give a detailed introduction virtually Selenium WebDriver?
Selenium 1 (Selenium IDE + selenium RC + Selenium Grid)
Selenium 2 (Selenium IDE + Selenium RC + Selenium WebDriver + Selenium Grid)
Note: Selenium WebDriver merged alongside Selenium 1 as well as called every bit Selenium 2.
• It is a most of import tool inwards Selenium suite.
• It is has programming interface allows us to practice as well as execute Test cases against dissimilar browsers (ex: Firefox, IE, Google Chrome etc...)
• WebDriver supports diverse programming languages(Java, .Net, PHP, Perl, Python as well as Ruby) to elevate Test cases.
• WebDriver supports diverse operating environments (MS Windows, UNIX as well as Macintosh etc...) to practice as well as execute Test cases.
• WebDriver supports Data Driven testing, Cross browser testing.
• Webdriver is faster than other tools inwards Selenium suite.
• WebDriver supports Parallel assay execution alongside the aid of TestNG.
• WebDriver doesn't convey IDE, alone Programming interface.
• WebDriver doesn't convey built inwards Result reporting facility, it provides summary only.
(* alongside the aid of TestNG nosotros tin generate HTML assay reports.)
• No object Repository inwards selenium WebDriver (This limitation is for entire Suite), therefore no centralized maintenance of Objects).
• Using Element locators, Webdriver methods as well as Java programming features nosotros tin createand execute Test cases.
2) How to gear upward Selenium WebDriver Environment?
• Download as well as install Java (JDK) software - to elevate assay cases using Java programming features.
• Set Path surround variable- to access Java from whatsoever directory.
• Download Eclipe IDE as well as extract
• Download WebDriver Java Language binding as well as add together Webdriver jounce files (in Eclipse)
• Install Firebug as well as FirePath plug ins for Mozilla Firefox browser to inspect Elements.
Note: For Internet Explorer as well as Google chrome, no require to install whatsoever plug ins, They convey built inwards Developer tools.
Note 2: Element locators as well as WebDriver methods are mutual for all browsers, browser driver alone varies from i browser to another.
Note 3: Firefox driver is default driver inwards Webdriver, For IE as well as Chrome nosotros require to download drivers.
Download Selenium WebDriver Java binding from www.seleniumhq.org website as well as extract.
Navigation for adding Webdriver jounce files inwards Eclipse.
Create Java projection inwards Eclipse
> Select src as well as correct click
> Build path
> Configure Build Path
> direct Libraries tab
> Click "Add External JARs
> Browser path of the WebDriver jars
> Add
3) How to practice Test cases using Selenium WebDriver?
• Using Element locators, WebDriver methods as well as Java programming features nosotros tin practice Test cases.
• Element locators for recognizing objects/elements.
• WebDriver Methods are used perform operatopns on Elements or objects.
• Java Programming for enhancting Test cases.
4) What are the Testing frameworks back upward Selenium WebDriver alongside Java?
JUnit
TestNG
We tin job either JUnit or TestNG testing framework alongside Java as well as Webdriver
5) What are the Element Locators that Selenium WebDriver supports to recognize Elements?
Selenium Webdriver supports eight Element locators to recognize Objects/Elements.
i) id
ii) name
iii) className
iv) tagName
v) linkText
vi) partialLinkText
vii) cssSelector
viii) xpath
Note: We tin job whatsoever i unique locator to recognize the Object/Element.
6) What is Cross Browser Testing?
Testing spider web applications using multiple browsers, Cross browser testing involves checking compatibility of the application.
7) How to comport Cross Browser Testing using WebDriver?
• Using Browser Drivers nosotros tin comport Cross browser testing.
• For Mozilla Firefox, nosotros no require to download the browser driver.
• For IE as well as Chrome etc... browsers download the browser drivers as well as laid path.
Create Browser Driver Object for Mozilla Firefox:
WebDriver driver = novel FirefoxDriver();
Create Browser Driver Object for Internet Explorer:
System.setProperty("webdriver.ie.driver", "E:/IEDriverServer.exe");
WebDriver driver = novel InternetExplorerDriver();
Create Browser Driver Object for Google Chrome:
System.setProperty("webdriver.chrome.driver", "E:/chromedriver.exe");
WebDriver driver = novel ChromeDriver();
8) What are the of import operations on Browser object?
Operation: Open URL
WebDriver code: driver.get("http:/google.com");
Operation: Return Browser Title
WebDriver code: String s = driver.getTitle();
Operation: Return Current URL
WebDriver code: String s = driver.getCurrentUrl();
Operation: Close focused Browser
WebDriver code: driver.close
Operation: Close all Browsers that opened past times WebDriver
WebDriver code: driver.quit
9) What are the Elements/Objects inwards Web Applications?
Link
Button
Image, Image Link, Image Button
Text box
Edit Box
Text Area
Check box
Radio Button
Drop downward box
List box
Combo box
Web tabular array /HTML table
Frame
Etc...
10) Write a Test illustration using Selenium WebDriver?
Manual Test Case:
Test Case Name: Admin Login
Steps:
i) Launch the Browser as well as navigate to www.gcrit/build3/admin/
ii) Enter user name
iii) Enter Password
iv) Click Login button
Verification point:
--------------------
Check the existance of "Logoff" link, if exists as well as then exceed otherwise fail
Selenium Test Case:
WebDriver driver = novel FirefoxDriver();
driver.get("http://www.gcrit.com/build3/admin/");
driver.findElement(By.name("username")).sendKeys("admin");
driver.findElement(By.name("password")).sendKeys("admin@123");
driver.findElement(By.id("tdb1")).click();
if (driver.findElement(By.linkText("Logoff")).isDisplayed()){
System.out.println("Login Successful");
}
else {
System.out.println("Login Failed");
}
11) How to comport Batch Testing using WebDriver?
Using TestNG Annotations nosotros tin grouping Test cases as well as execute serial of Test cases.
12) How to stimulate Link element?
Operation: Click Link
WebDriver code: driver.findElement(By.linkText("Gmail")).click();
Operation: Check the link existance
WebDriver code:
boolean a = driver.findElement(By.xpath(".//*[@id='gbw']/div/div/div[1]/div[1]/a")).isDisplayed();
System.out.println(a); //true
Operation: Check the link enabled status
WebDriver code:
boolean b = driver.findElement(By.xpath(".//*[@id='gbw']/div/div/div[1]/div[1]/a")).isEnabled();
System.out.println(b); //true
Operation: Return the Link Name
WebDriver code:
String c = driver.findElement(By.xpath(".//*[@id='gbw']/div/div/div[1]/div[1]/a")).getText();
System.out.println(c); //Gmail
13) How to stimulate Button element?
Important operations on Buttons:
Enabled status
Display status
Click
Return rear of the Button
type of the object
Example:
public static void main(String[] args) {
WebDriver driver = novel FirefoxDriver();
driver.get("https://gmail.com");
WebElement push = driver.findElement(By.id("next"));
boolean a = button.isDisplayed();
boolean b = button.isEnabled();
button.getAttribute("name");
button.getAttribute("type");
button.click();
System.out.println(a);
System.out.println(b);
}
14) How to stimulate Edit box element?
Important Operations on Edit box:
Enter a Value,
Clear the Value,
Check enabled status,
Check edit box existence,
Get the value etc...
----------------------------
Example:
public static void main(String[] args) {
WebDriver driver = novel FirefoxDriver();
driver.get("https://gmail.com");
//Enter a Value
driver.findElement(By.id("Email")).sendKeys("ABCD123");
//Return the Value
String value = driver.findElement(By.id("Email")).getAttribute("name");
//Return Type of the Object
String value2 = driver.findElement(By.id("Email")).getAttribute("type");
//Return display status
boolean a = driver.findElement(By.id("Email")).isDisplayed();
//Return Enabled status
boolean b = driver.findElement(By.id("Email")).isEnabled();
System.out.println(value);
System.out.println(value2);
System.out.println(a);
System.out.println(b);
// Clear the Value
driver.findElement(By.id("Email")).clear();
}
}
15) How to stimulate Images?
Three types of Image elements inwards Web Environment
1) General Image (No functionality)
2) Image Button (Submits)
3) Image Link (Redirects to unopen to other page/location)
Example:
public static void main(String[] args) {
WebDriver driver = novel FirefoxDriver();
driver.get("https://google.com");
String Title = driver.findElement(By.id("hplogo")).getAttribute("Title");
System.out.println(Title);
driver.navigate().to("http://newtours.demoaut.com/");
driver.findElement(By.name("login")).click();
driver.navigate().to("http://www.seleniumhq.org/");
driver.findElement(By.xpath(".//*[@id='choice']/tbody/tr/td[2]/center/a/img")).click();
}
16) How to stimulate Radio Button element?
Operations on Radio Button
i) Select Radio Button
ii) Verify if the Radio Button is Displayed or not?
iii) Verify if the Radio Button is enabled or not?
iv) Verify if the Radio Button is Selected or not?
---------------------
Example:
public static void main(String[] args) {
WebDriver driver = novel FirefoxDriver();
driver.get("http://www.gcrit.com/build3/create_account.php?osCsid=boh81f11tmud1134jnp5ne7r20");
boolean a = driver.findElement(By.xpath(".//*[@id='bodyContent']/form/div/div[2]/table/tbody/tr[1]/td[2]/input[1]")).isDisplayed();
System.out.println(a); //true
boolean b = driver.findElement(By.xpath(".//*[@id='bodyContent']/form/div/div[2]/table/tbody/tr[1]/td[2]/input[1]")).isEnabled();
System.out.println(b); //true
boolean c = driver.findElement(By.xpath(".//*[@id='bodyContent']/form/div/div[2]/table/tbody/tr[1]/td[2]/input[1]")).isSelected();
System.out.println(c); //false
driver.findElement(By.xpath(".//*[@id='bodyContent']/form/div/div[2]/table/tbody/tr[1]/td[2]/input[1]")).click();
boolean d = driver.findElement(By.xpath(".//*[@id='bodyContent']/form/div/div[2]/table/tbody/tr[1]/td[2]/input[1]")).isSelected();
System.out.println(d); //true
driver.findElement(By.xpath(".//*[@id='bodyContent']/form/div/div[2]/table/tbody/tr[1]/td[2]/input[1]")).clear();
}
17) How to stimulate Check box element?
Operations on Check box
i) Check if the cheque box is displayed or not?
ii) Check if the cheque box is enabled or not?
iii) Check if the cheque box is Selected or not?
iv) Select the Check box
v) Unselect the Check box
Example:
public static void main(String[] args) {
WebDriver driver = novel FirefoxDriver();
driver.get("file:///E:/HTMLExamples/MultipleCheckbox.html");
boolean display = driver.findElement(By.xpath("html/body/input[2]")).isDisplayed();
System.out.println("Displayed Status: " + display);
boolean enabled = driver.findElement(By.xpath("html/body/input[2]")).isEnabled();
System.out.println("Enabled Status: " + enabled);
boolean cheque = driver.findElement(By.xpath("html/body/input[2]")).isSelected();
System.out.println("Check Status: " + check);
driver.findElement(By.xpath("html/body/input[2]")).click();
boolean check2 = driver.findElement(By.xpath("html/body/input[2]")).isSelected();
System.out.println("Check Status: " + check2);
driver.findElement(By.xpath("html/body/input[2]")).click();
boolean check3 = driver.findElement(By.xpath("html/body/input[2]")).isSelected();
System.out.println("Check Status: " + check3);
}
18) How to stimulate Frames?
• HTML frames are used to dissever our Browser window into multiple sections,
where each department tin charge a separate html document.
• Frames are sections of Web page displayed on tiptop window.
• Whenever nosotros access the page as well as then focus is on the tiptop window.
Switch to a frame is done inwards 2 ways:--------------------------------------
i) Using frame index
Syntax:
driver.switchTo.frame(int index);
ii) Using frame name
Syntax:
driver.switchTo.frame(String name);
Example:
//Using Frame index
public static void main(String[] args) {
WebDriver driver = novel FirefoxDriver();
driver.get("http://seleniumhq.github.io/selenium/docs/api/java/index.html");
driver.switchTo().frame(0);
driver.findElement(By.xpath("html/body/div[2]/ul/li[1]/a")).click();
}
-------------------------------
//Using Frame name
public static void main(String[] args) {
WebDriver driver = novel FirefoxDriver();
driver.get("http://seleniumhq.github.io/selenium/docs/api/java/index.html");
driver.switchTo().frame("packageListFrame");
driver.findElement(By.xpath("html/body/div[2]/ul/li[1]/a")).click();
}
---------------------------------
Switch from a frame to Top window:
driver.switchTo().defaultContent();
Example:
public static void main(String[] args) {
WebDriver driver = novel FirefoxDriver();
driver.get("http://seleniumhq.github.io/selenium/docs/api/java/index.html");
//Switch from Top window to third frame
driver.switchTo().frame(2);
driver.findElement(By.xpath("html/body/div[3]/table/tbody[2]/tr[1]/td[1]/a")).click();
//Switch from third frame to Top window
driver.switchTo().defaultContent();
//Switch from Top window to 1st frame
driver.switchTo().frame(0);
driver.findElement(By.xpath("html/body/div[2]/ul/li[1]/a")).click();
}
}
19) How to stimulate Web Table?
Important Operations on Web Table:
Get prison theatre mobile telephone value
Rows Count
Cells Count
Example:
public static void main(String[] args) {
WebDriver driver = novel FirefoxDriver();
driver.get("file:///E:/HTMLExamples/htmlTable.html");
String s = driver.findElement(By.xpath(".//*[@id='students']/tbody/tr[2]/td[2]")).getText();
System.out.println(s);
WebElement htmlTable = driver.findElement(By.id("students"));
List <WebElement> rows = htmlTable.findElements(By.tagName("tr"));
int i = rows.size();
System.out.println(i);
List <WebElement> cells = htmlTable.findElements(By.tagName("td"));
int j = cells.size();
System.out.println(j);
}
20) How to stimulate Multiple Browsers?
We tin Handle Multiple Browsers using Browser window handle.
21) How to stimulate duplicate elements/objects?
We tin Handle duplicate objects/elements using index, index starts from 0 to ix as well as Top left of the spider web page to Bottom right.
--------------------------------------------
Selenium Interview Questions-1
Selenium Interview Questions-2
Java for Selenium Interview Questions
Selenium WebDriver Questions
Selenium IDE Questions
TestNG Interview Questions