71) How to handle frames in Selenium WebDriver?
Select a frame by its (zero-based) index.
driver.switchTo().frame(int arg0);
72) What is the difference between driver.close() and driver.quit command?
73) How to handle web based alerts in Selenium WebDriver?
There are the four methods that we would be using along with the Alert interface.
Syntax:
// accepting javascript alert
Alert alert = driver.switchTo().alert();
alert.accept();
74) How do you verify if the checkbox/radio is checked or not ?
driver.findElement(By.xpath("xpath of the checkbox/radio button")).isSelected();
75) How do you clear the contents of a textbox in selenium?
Use clear() method.
driver.findElement(By.xpath("xpath of box")).clear();
76) How do you handle https website in selenium?
FirefoxProfile profile = new FirefoxProfile();
profile.setAcceptUntrustedCertificates(false);
WebDriver driver = new FirefoxDriver(profile);
driver.get("url");
77) How to switch back from a frame?
driver.switchTo().defaultContent();
78) How to press Shift+Tab?
String press = Keys.chord(Keys.SHIFT,Keys.ENTER);
webelement.sendKeys(press);
79) How to check all checkboxes in a page?
List<webElement> chkBox = driver.findElements(By.xpath(“//htmltag[@attbute='checkbox']”));
for(int i=0; i<=chkBox.size(); i++){
chkBox.get(i).click();
}
80) Count the number of links in a page.
JavascriptExecutor jsx = (JavascriptExecutor)driver;
List<webElement> link = driver.findElements(By.tagName(“a”));
System.out.println(link.size());
81) How do you simulate scroll down action?
JavascriptExecutor jsx = (JavascriptExecutor)driver;
jsx.executeScript("window.scrollBy(0,4500)", ""); //scroll down
Thread.sleep(3000);
jsx.executeScript("window.scrollBy(450,0)", ""); //scroll up
Select a frame by its (zero-based) index.
driver.switchTo().frame(int arg0);
- Select a frame using its previously located WebElement.
- Locating iframe using tagName
- Switch to the frame by Name
72) What is the difference between driver.close() and driver.quit command?
- close(): WebDriver’s close() method closes the web browser window that is being currently accessed by the WebDriver. The command neither requires any parameter nor does is return any value.
- quit(): quit() method closes down all the windows that the program has opened. Same as close() method, the command neither requires any parameter nor does is return any value.
73) How to handle web based alerts in Selenium WebDriver?
There are the four methods that we would be using along with the Alert interface.
- void dismiss():- The accept() method clicks on the “Cancel” button as soon as the pop up window appears.
- void accept():- The accept() method clicks on the “Ok” button as soon as the pop up window appears.
- String getText():- The getText() method returns the text displayed on the alert box.
- void sendKeys(String stringToSend):- The sendKeys() method enters the specified string pattern into the alert box.
Syntax:
// accepting javascript alert
Alert alert = driver.switchTo().alert();
alert.accept();
74) How do you verify if the checkbox/radio is checked or not ?
driver.findElement(By.xpath("xpath of the checkbox/radio button")).isSelected();
75) How do you clear the contents of a textbox in selenium?
Use clear() method.
driver.findElement(By.xpath("xpath of box")).clear();
76) How do you handle https website in selenium?
FirefoxProfile profile = new FirefoxProfile();
profile.setAcceptUntrustedCertificates(false);
WebDriver driver = new FirefoxDriver(profile);
driver.get("url");
77) How to switch back from a frame?
driver.switchTo().defaultContent();
78) How to press Shift+Tab?
String press = Keys.chord(Keys.SHIFT,Keys.ENTER);
webelement.sendKeys(press);
79) How to check all checkboxes in a page?
List<webElement> chkBox = driver.findElements(By.xpath(“//htmltag[@attbute='checkbox']”));
for(int i=0; i<=chkBox.size(); i++){
chkBox.get(i).click();
}
80) Count the number of links in a page.
JavascriptExecutor jsx = (JavascriptExecutor)driver;
List<webElement> link = driver.findElements(By.tagName(“a”));
System.out.println(link.size());
81) How do you simulate scroll down action?
JavascriptExecutor jsx = (JavascriptExecutor)driver;
jsx.executeScript("window.scrollBy(0,4500)", ""); //scroll down
Thread.sleep(3000);
jsx.executeScript("window.scrollBy(450,0)", ""); //scroll up
<-- Previous
No comments:
Post a Comment