Search: Skip To Content Using Gmail With Screen Readers
Search: Skip To Content Using Gmail With Screen Readers
Search: Skip To Content Using Gmail With Screen Readers
Skip to content
Using Gmail with screen readers
Search
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
3.141.59
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?
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
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?
WebElement represents an HTML element. Generally, all operations on a web page will be performed
How do you launch the browser using WebDriver?
//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?
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:
To get the title, we will use getTitle() method and here is the code:
driver.findElement(By.name(“txtboxname”)).clear() ;
StringstrText=driver.findElement(By.name(“txtboxname”)).getAttribute(“value”);
//to print the text
System.out.println(strText);
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);
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”);
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?
System.out.println(str.size());
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);
intwdth=element.getSize().getWidth();
intht=element.getSize().getHeight();
System.out.println(intwidth);
System.out.println(intht);
}
}
List<WebElement> allchkBox=driver.findElements(By.xpath(“//input[@type=’checkbox’]”));
for(inti=0;i<allchkBox.size();i++){
allchkBox.get(i).click();
}
}
}
It is used to deselect all the web elements which have been selected earlier.
listbox.deselectAll();
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.
findElements( ):
Find all elements within the current page using the given locator.
FilescrFile=((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE);
FileUtils.copyFile(scrFile,newFile(“D:\\Test.jpg”));
To get screenshot on test failure, we should put the entire code in try-catch block. In the catch block ma
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”));
}
}
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();
driver.get(“https://google.com/”);
driver.get(driver.getCurrentUrl());
driver.get(“https://google.com/”);
driver.findElement(By.xpath(“xpath”)).sendKeys(Keys.F5) ;
driver.navigate().forward();
//Navigate – Back
driver.navigate().back();
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:
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();
driver.findElement(By.xpath(“xpath”)).sendKeys(“D:\\test.txt”) ;
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();
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();
driver.get():
driver.get() method i
...
ReplyForward