Search: Skip To Content Using Gmail With Screen Readers

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 11

Basic HTML view

Skip to content
Using Gmail with screen readers

Search

Enable desktop notifications for Gmail.      OK    N o th an k s

Compose

Labels
Inbox
6,028
Starred
Snoozed
Sent
Drafts
4
[Imap]/Sent
[Imap]/Trash
663
More
 

Hangouts

 
 
More

4 of 7,498

sele
Kavitha
to me

MENU Selenium FAQs


Home / Selenium FAQs
Selenium WebDriver
What is the latest version of Selenium?

3.141.59

What is locator and different locators in Selenium?

Locator can be termed as an address that identifies a web element uniquely within the webpage. Thus,
we have different types of locators in Selenium:
1.       Id
2.       Name
3.       LinkText
4.       Partial LinkText
5.       Tag Name
6.       Class name
7.       CSS
8.       xPath
What are the limitations of Selenium?

Technical challenges with Selenium are:


1.       Selenium supports only web based applications.
2.       It does not support the Bitmap comparison.
3.       For any reporting related capabilities have to depend on third party tools.
4.       No vendor support for tool compared to commercial tools like QTP/UFT.
5.       As there is no object repository concept in Selenium, maintainability of objects becomes difficult.
What’s the difference between “/” and “//” in xPath?

xPath is used to locate a web element based on its XML path. xPath can be used to locate HTML eleme

Single Slash (/) – Single slash is used to create Xpath with absolute path i.e. the xPath would be created to start selection from

Double Slash (//) – Double slash is used to create xPath with relative path i.e. the xPath would be created to start selection fro

What is Absolute and Relative xPath?

Absolute xPath: Writing the complete path of a specified element with tags using single forward slash (
consuming and lengthy. Here the single slash (‘/’) represents immediate child.

Example: html/body/div[7]/div[3]/div/div[2]/div[1]/span

Relative xPath: Writing the path of a specific element using double forward slash with parent tag (‘//’) is known as Relative x
called as Descendants.

Example: //table[@class=’dataTable’]/tbody/tr[1]
What is WebDriver?

WebDriver is a component from Selenium to automate web applications, and in particular to verify tha
friendly API that’s easy to explore and understand.
What are the different types of Drivers available in WebDriver?

The different drivers available in WebDriver are:


1.       FirefoxDriver
2.       InternetExplorerDriver
3.       ChromeDriver
4.       SafariDriver
5.       OperaDriver
6.       AndroidDriver
7.       IPhoneDriver
8.       HtmlUnitDriver
What is WebElement?

WebElement represents an HTML element. Generally, all operations on a web page will be performed
How do you launch the browser using WebDriver?

The following syntax can be used to launch Browser:

//Firefox

System.setProperty(“webdriver.gecko.driver”, “C:\\Nagesh\\Lib\\geckodriver.exe”);
WebDriver driver = new FirefoxDriver();

//Chrome

System.setProperty(“webdriver.chrome.driver”, “C:\\Nagesh\\Lib\\chromedriver.exe”);
WebDriver driver = new ChromeDriver();

//IE

System.setProperty(“webdriver.ie.driver”, “C:\\Nagesh\\Lib\\IEDriverServer.exe”);
WebDriver driver = new InternetExplorerDriver();
How do you open the Gmail in Firefox browser?

The Code is:

WebDriver driver =new FirefoxDriver();


driver.get(“http://www.gmail.com”);

How do you open a site using chrome browser?


 public class ChromeBrowser{
public static void main(Stringargs[]){

//Set System property for chrome driver


System.setProperty(“webdriver.chrome.driver”,”D://Jars//chromedriver.exe”);
WebDriver driver=new ChromeDriver();
driver.get(“http://www.google.com/”);
}
}

How do you open a site using IE browser?

Public class IEBrowser{


publicstaticvoid main(Stringargs[]){

//Set System property for IE driver


System.setProperty(“webdriver.ie.driver”,”d://Jars//IEDriverServer.exe”);
WebDriver driver=new InternetExplorerDriver();
driver.get(“http://www.google.com/”);
}
}

How can we get a text of a Web Eelement?


 getText() command is used to retrieve the inner text of the specified web element. The command doesn
value.

Sample Code:

String strTxt=driver.findElement(By.id(“Text”)).getText();
System.out.println(strTxt);
How do you maximize the browser?

To maximize a web browser, WebDriver providers a built-in method and here is the syntax:

WebDriver driver =new FirefoxDriver();


//to maximize the browser
driver.manage().window().maximize
Write a code to get the title of a page?

To get the title, we will use getTitle() method and here is the code:

WebDriver driver =new FirefoxDriver();


driver.get(“http://wwww.google.com”);
//to get the title
String strTitle = driver.getTitle();
//to print the title
System.out.println(strTitle);
Write a code to enter and clear value in a text box?
Entering values in Text Box:
sendKeys() method is used to enter the value into the text boxes.
driver.findElement(By.name(“txtboxname”)).sendKeys(“Test”);

Clearing Values in Text Box:


clear() method is used to clear the text box.

driver.findElement(By.name(“txtboxname”)).clear() ;

Write a code to read the text box value?

By using, getAttribute() method we can get the value of the text box.

StringstrText=driver.findElement(By.name(“txtboxname”)).getAttribute(“value”);
//to print the text
System.out.println(strText);

How do you get the typed text in a textbox?

Use getAttribute() method to get the value of a typed text in the textbox and pass “value” as an argume

StringstrText=driver.findElement(By.xpath(“Xpath”)).getAttribute(“value”);
System.out.println(strText);

How can you find if an element is displayed on the screen?

The visibility of the WebElements can find using the following methods:
1.       isDisplayed()

Sample Code:

isDisplayed():
if{

(driver.findElement(By.name(“username”)).isDisplayed());

System.out.println(“Available”);

}else{

System.out.println(“Not Available”);

How do you print all links on a page?

List<WebElement> str= driver.findElements(By.tagName(“a”));

System.out.println(str.size());
for (int i = 0; i < str.size(); i++) {

if(!str.get(i).getText().equalsIgnoreCase(“”))

System.out.println(str.get(i).getText());  //str[i]

              }
How do you print all dropdowns on a page?

List<WebElement> str= driver.findElements(By.tagName(“select”));

System.out.println(str.size());

for (int i = 0; i < str.size(); i++) {

System.out.println(“dropdown locator is :”+str.get(i).getAttribute(“name”));

How do you verify if the checkbox or radio is selected or not?

By Using isSelected() method, we can identify whether it is selected or not. The return type of the meth
is selected else it is not selected.

Boolean b =driver.findElement(By.xpath(“Xpath”)).isSelected();
System.out.println(b);

Write a code to clear the contents of a textbox?


 driver.findElement(By.xpath(“xpath of the textbox”)).clear
How do you get Width & Height of a text box?
 public class Width_Height{

public static void main(String[] args){

WebDriver driver=new FirefoxDriver();


driver.get(“http://wwww.google.com”);
WebElement element=driver.findElement(By.xpath(“xpath of a textbox”));

intwdth=element.getSize().getWidth();
intht=element.getSize().getHeight();

System.out.println(intwidth);
System.out.println(intht);
}
}

How to check all checkboxes in a page?


 public class Check_all_checkbox{

public static void main(String[] args){


WebDriver driver=new FirefoxDriver();
driver.get(“http://www.echoecho.com/htmlforms09.htm”);

List<WebElement> allchkBox=driver.findElements(By.xpath(“//input[@type=’checkbox’]”));

for(inti=0;i<allchkBox.size();i++){

allchkBox.get(i).click();
}
}
}

What is the use of deSelectAll() method?

It is used to deselect all the web elements which have been selected earlier.

listbox.deselectAll();

What is the use of getOptions() method?

getOptions() is used to get all the values from the dropdown


What is the use of getAllSelectedOptions() method?

getAllSelectedOptions() is used to get only the selected values from the list dropdown
What is the difference between findElement() and findElements()?

findElement( ):

Find the first element within the current page using the locators.

Returns a single WebElement.

If element not found, will throw the exception like NoSuchElementException.

findElements( ):

Find all elements within the current page using the given locator.

Returns List of WebElements.


If element not found it will return empty List of WebElement object.

What is the difference between driver.close() and driver.quit()?

close(): close() method closes the child window.


quit(): quit() method closes the main browser and also all the windows that the program has opened.
How to capture screenshot in WebDriver?
 The sample code to take screenshot of webpage is:

FilescrFile=((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE);
FileUtils.copyFile(scrFile,newFile(“D:\\Test.jpg”));

How to capture screenshot in WebDriver for a failed case?

To get screenshot on test failure, we should put the entire code in try-catch block. In the catch block ma

Public class TakeScreenshot{

WebDriver driver;

@BeforeTest
public void start(){
driver=newFirefoxDriver();
}

@Test
public void test() throws Exception{
try{
driver.get(“https://google.com/”);
//find the element with wrong xpath, so control moves to catch block
driver.findElement(By.xpath(“Wrong Xpath”)).sendKeys(“Testing”);

}catch(Exception e){
//Takes the Screenshot and saves in the path mentioned when test fails
File scrFile=((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE);
FileUtils.copyFile(scrFile,newFile(“D:\\Test.png”));

}
}

How to refresh a web page using WebDriver?

The following are the various methods available in WebDriver to refresh the page:
1.       Using refresh() method:

driver.get(“https://google.com/”);
driver.navigate().refresh();

2.       Using to() method:


driver.get(“https://google.com/”);
driver.navigate().to(driver.getCurrentUrl());

3.       Using get() method:

driver.get(“https://google.com/”);
driver.get(driver.getCurrentUrl());

4.       Using SendKeys method:

driver.get(“https://google.com/”);
driver.findElement(By.xpath(“xpath”)).sendKeys(Keys.F5) ;

How do you navigate browser back and forward?


 //Navigate – Forward

driver.navigate().forward();

//Navigate – Back
driver.navigate().back();

How do you handle alert pop-up?

By using “Alert” class you can handle pop-up’s. First move control to alert pop-up’s, then move back c
The Sample code is:

WebDriver driver=new FirefoxDriver();


driver.get(“http://xyz.com”);

//Move control to alert pop up


Alert alt=driver.switchTo().alert();
//to click “Ok”
alt.accept();
//Or
//to click “Cancel”
alt.dismiss();

How to perform right click using WebDriver?

Method 1: Using Actions class

// the element on which the right click to be performed


WebElement element=driver.findElement(By.xpath(“//a[@href=’username’]”));
Actions action=new Actions(driver);
action.moveToElement(Webelement);
//this will perform right click
action.contextClick(Webelement).build().perform();

Method 2: Using ContextClick()


WebElement element=driver.findElement(By.xpath(“//a[@href=’username’]”));
// Initialize Actions class object
Actions builder=new Actions(driver);
//ContextClick() is a method to right click
builder.contextClick(element).sendKeys(Keys.ARROW_DOWN).sendKeys(Keys.ENTER).build().perform();

How do you perform drag and drop using WebDriver?


 Method 1:

Actions act=newActions(driver);
WebElement source=driver.findElement(By.xpath(“source xpath”));
WebElement target=driver.findElement(By.xpath(“target xpath”));
act.dragAndDrop(source, target).build().perform();

Method 2:

act.clickAndHold(source).build().perform();
act.moveToElement(target).build().perform();
act.release(target).build().perform();

Method 3:

act.dragAndDropBy(source,xoffset,yoffset).perform();

Write a code to upload a file?


 //Syntax – sendKeys(“file to be uploaded”);

driver.findElement(By.xpath(“xpath”)).sendKeys(“D:\\test.txt”) ;

What is the difference between getWindowHandles() and getWindowHandle( )?

getWindowHandles() – is used to get all the open browser from the current execution and its return typ
getWindowHandle() – is used to get the address of the current browser where the control is and return
How to switch between windows?
 Set<String> str = driver.getWindowHandles();

System.out.println(“The windows are :”+str);

Object[] s = str.toArray();

driver.switchTo().window(s[1].toString());

driver.findElement(By.id(“name”)).sendKeys(“Testing”);

driver.findElement(By.id(“email”)).sendKeys(“[email protected]”);

driver.close();
driver.switchTo().window(s[0].toString());

driver.findElement(By.linkText(“ADT”)).click();

What is the difference between driver.get() and driver.navigate() methods?

driver.get():

driver.get() method i

...

[Message clipped]  View entire message


9 Attachments
 
 

ReplyForward

You might also like