Untitled
Untitled
ImplicitWait ExplicitWait
1) We do not specify any condition We should specify the condition
2) We can only handle findElement() and We can handle any method
findElements()
3) After the timeout we get After the timeout we get TimeOutException
NoSuchElementException
4) Time unit can be DAYS,HOURS,SECONDS etc It can be only SECONDS
IQ8) Write a script to login and logout from the application without specifying any type of waiting
duration(period)
26
public static void main(String[] args)
{
//script to login to actitime
//open the browser
WebDriver driver=new FirefoxDriver();
//enter the url
driver.get("http://localhost/login.do");
//enter the username
driver.findElement(By.id("username")).sendKeys("admin");
//enter the password
driver.findElement(By.name("pwd")).sendKeys("manager");
//click on login button
driver.findElement(By.xpath("//div[text()='Login ']")).click();
while(true)
{
try
{
driver.findElement(By.id("logoutLink")).click();
break;
}
catch(Exception e)
{
}
}
}
}
IQ9) How do you click on a button without using click()
import org.openqa.selenium.By;
import org.openqa.selenium.Keys;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
IQ10) How do you change the value present in the text box Ans:
27
WebElement un=driver.findelement(By.id(“username”));
Un.clear();
Un.sendkeys(“bhanu”);
IQ11) How do you remove the value present in the text box without using clear() Ans:
un.sendkeys(Keys.CONTROL+”a”+Keys.DELETE);
IQ12)Write a script to copy paste the value present in one text box into another text box Ans:
un.sendkeys(Keys.CONTROL+”ac”+Keys. CONTROL+”v”);
String v=un.getAttribute(“value”);
System.out.println(v)
Limitation1:
using getAttribute(“title”)
import org.openqa.selenium.By;
import org.openqa.selenium.Keys;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.By;
import org.openqa.selenium.Keys;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
28
public static void main(String[] args)
{
WebDriver driver = new FirefoxDriver();
driver.get("https://demo.vtiger.com/");
WebElement chkBox=driver.findElement(By.name("remeber"));
String tt = chkBox.getAttribute("title");
System.out.println("tt");
}
IQ16)What is the difference between getAttribute() & getText()
Ans: getAttribute() get the value of the specified attribute where as getText() is used to get the text of
the specified element
29
public class Demo622016 {
}
IQ19)Write a code to print font size and color of the username text box in actiTime application
import org.openqa.selenium.By;
import org.openqa.selenium.Dimension;
import org.openqa.selenium.Point;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
System.out.println(ff);
driver.close();
OUTPUT:
14px
Rgba(0,0,0,1)
MS Shell Dlg\32
30
IQ20)Write a script to verify that login button is enabled
import org.openqa.selenium.By;
import org.openqa.selenium.Dimension;
import org.openqa.selenium.Point;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
driver.close();
}
IQ21)Write a script to verify that Next button in the gmail login page is visble(hint:using isDisplayed())
IQ22)Write a script to verify whether keep me logged in checkbox present in facebook login page is
selected or not?(hint:isSelected())
Note:
1. clear()
2. click()*
3. getAttribute()*
4. getCssValue()
5. getLocation()
6. getSize()
7. getTagName()
8. getText()*
9. isDisplayed()
10. isEnabled()
11. isSelected()
31
12. sendKeys()*
13. submit()
last page:
InvalidStateElementException(Unchecked Selenium Exception)
Step#3:Type the javascript statement in the text box which is available at rite the java script statement
in the text box which is available at the bottom of the firebug window and press enter
Hi..!!
OK
>alert(‘hi’)
32
I I I
WEB DRIVER
JavascriptExecutor
excecuteScript(Str)
Close();
C RemoteWebDriver C
Close() {}
executeScript(Str){}
FirefoxDriver C C chromeDriver
else{} else{}
Executescript(Str){} executeScript(Str){}
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.remote.RemoteWebDriver;
}}
IQ24) Write a script to enter the text into text box without using sendKeys()
import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.remote.RemoteWebDriver;
33
public static void main(String[] args) {
WebDriver driver = new FirefoxDriver();
driver.get("https://demo.vtiger.com/");
String c = "document.getElementById('username').value='abc'";
JavascriptExecutor j = (JavascriptExecutor) driver;
j.executeScript(c);
}
}
IQ25**) How do you enter the text if the text box is disabled using JavaScript
<html>
<body>
</body>
</html>
WebDriver driver = new FirefoxDriver();
driver.get("file:///c:/demo.html");
String c = "document.getElementById('username').value='bhanu'";
JavascriptExecutor j = (JavascriptExecutor) driver;
j.executeScript(c);
(hint: find the x and y co-ordinates of the element using getLocation(),pass them as argument for javaScript)
Driver.findElement(By.id(“”)).getLocation()
Window.scrollTo(x,y)
import java.io.File;
import java.io.IOException;
import org.apache.commons.io.FileUtils;
import org.openqa.selenium.OutputType;
34
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.support.events.EventFiringWebDriver;
NOTE:
Limitation:
*using selenium we can take screen shot in PNG(portable network graphics) format only.we can not take the
screenshot of popups,we cannot take screenshot of specific area in the page,we can not take the screenshot of
multiple browser or desktop
* If the page is very lengthy it will automatically takes the screenshot of complete page.
ENCAPSULATION
“Process of hiding the data and binding with methods is called as encapsulation.”
Example:
public class A
private int i;
public A()
i=10;
35