Important questions & answers with &without selenium
1.write a script for to open browser?
without selenium
Ans: using autoit
Ans: using autoit
Runtime.getRuntime().exec("C:\\Program Files (x86)
\\Mozilla Firefox\\firefox.exe");
\\Mozilla Firefox\\firefox.exe");
2.write a script to maximize the browser?
using selenium
Ans: driver.manage().window().maximize();
Ans: driver.manage().window().maximize();
without selenium:
Ans: Robot r=new Robot();
Ans: Robot r=new Robot();
r.keyPress(KeyEvent.VK_ALT);
r.keyPress(KeyEvent.VK_TAB);
r.keyRelease(KeyEvent.VK_ALT);
r.keyRelease(KeyEvent.VK_TAB);
3.write script to minimixe the browser?
using selenium :
Ans:minimize not possible..
without selenium:
Ans:robot class
Ans:robot class
Robot r=new Robot();
r.keyPress(KeyEvent.VK_WINDOWS);
r.keyPress(KeyEvent.VK_M);
r.keyRelease(KeyEvent.VK_WINDOWS);
r.keyRelease(KeyEvent.VK_M);
4.Move the browser specfic location?
using selenium:
Ans:Point p=new Point(0,100);
driver.manage().window().setPosition(p);
without selenium:
Ans:difficult to write its take lenthy..just say using robot cls do..
Ans:difficult to write its take lenthy..just say using robot cls do..
5.Resize browser size?
using selenium:
Ans:Dimension d=new Dimension(10,10);
driver.manage().window().setSize(d);
without selenium:
Ans:difficult to write its take lengthy..just say using robot cls do..
Ans:difficult to write its take lengthy..just say using robot cls do..
6.change the URL present in the address bar?
using selenium:
Ans:driver.navigate().to("url");
without selenium:
Ans: Not possible
Ans:driver.navigate().to("url");
without selenium:
Ans: Not possible
7.How to refresh browser?
using selenium:
Ans:1.driver.navigate().Refresh():
2.driver.findElement(By.tagname("//html")).semdkeys(Keys.F5);
3.driver.navigate().to(driver.getcurrentUrl()):
without selenium
Ans:Robot r=new Robot();
r.keyPress(KeyEvent.VK_F5);
r.keyRelease(KeyEvent.VK_F5);
8.How to click on back button?
with selenium:
Ans:driver.navigate().back();
without selenium:
Ans:1 Robot r=new Robot();
Ans:1 Robot r=new Robot();
r.keyPress(KeyEvent.VK_ALT);
r.keyPress(KeyEvent.VK_LEFT);
r.keyRelease(KeyEvent.VK_ALT);
r.keyRelease(KeyEvent.VK_LEFT);
Ans:2 using autoit- mouseclick(100,35)
9.How to click on forward button?
with selenium:
Ans:driver.navigate().forward();
Ans:driver.navigate().forward();
without selenium:
Ans: Robot r=new Robot();
Ans: Robot r=new Robot();
r.keyPress(KeyEvent.VK_ALT);
r.keyPress(KeyEvent.VK_RIGHT);
r.keyRelease(KeyEvent.VK_ALT);
r.keyRelease(KeyEvent.VK_RIGHT);
10.How to close browser using close method ,without close method ,without close & quit method?
with selenium:
using close():
Ans:driver.close();
without close()
Ans:driver.quit();
without selenium:
without selenium:
without close & quit
Ans: Robot r=new Robot();
r.keyPress(KeyEvent.VK_ALT);
r.keyPress(KeyEvent.VK_F4);
r.keyRelease(KeyEvent.VK_ALT);
r.keyRelease(KeyEvent.VK_F4);
11.How to print the title of browser?
with selenium:Ans:No Answer
without selenium:
Ans:javascript
JavascriptExecutor js=(JavascriptExecutor) driver;
String name=(String) js.executeScript("return navigator.userAgent");
System.out.println(name);
12.How to print the URL present in the address bar?
with selenium:
Ans:driver.getCurrentURL();
without selenium:
Ans:No answer
Ans:driver.getCurrentURL();
without selenium:
Ans:No answer
13.How to print the source of the webpage?
with selenium:Ans:driver.getPage source();
without selenium:
Ans:No answer
14.How to type without using sendkeys in text box?
with selenium:Ans:No answer
without selenium:
Ans:1 JavascriptExecutor js=(JavascriptExecutor) driver;
Ans:1 JavascriptExecutor js=(JavascriptExecutor) driver;
String name=(String) js.executeScript("document.getElementById('jdhjhd').
value='admin'");
Ans:2 Robot r=new Robot();
r.keyPress(KeyEvent.VK_A);
r.keyPress(KeyEvent.VK_D);
r.keyPress(KeyEvent.VK_M);
r.keyPress(KeyEvent.VK_I);
r.keyPress(KeyEvent.VK_N);
r.keyRelease(KeyEvent.VK_A);
r.keyRelease(KeyEvent.VK_D);
r.keyRelease(KeyEvent.VK_M);
r.keyRelease(KeyEvent.VK_I);
r.keyRelease(KeyEvent.VK_N);
15.How to display text present in the text box?
with seleniumAns:driver.findElement(By.id("hghghgh")).sendKeys("admin");
String un = driver.findElement(By.id("hghghgh")).getAttribute("value");
System.out.println(un);
Ans:No answer
16.Write a script to remove text present in textbox?with clear method ,without
clear method ,without selenium?
clear method ,without selenium?
with selenium:
clear method()
Ans:driver.findElement(By.id("hghghgh")).clear();
clear method()
Ans:driver.findElement(By.id("hghghgh")).clear();
without clear():
Ans:driver.findElement(By.id("hghghgh")).sendKeys(Keys.CONTROL,"a");
without selenium:
Ans:driver.findElement(By.id("hghghgh")).sendKeys(Keys.CONTROL,"a");
driver.findElement(By.id("hghghgh")).sendKeys(Keys.DELETE);
Ans:Robot r=new Robot();
r.keyPress(KeyEvent.VK_CONTROL);
r.keyPress(KeyEvent.VK_A);
r.keyPress(KeyEvent.VK_DELETE);
r.keyRelease(KeyEvent.VK_CONTROL);
r.keyRelease(KeyEvent.VK_A);
r.keyRelease(KeyEvent.VK_DELETE);
17.Write script to clcik on button?with click ,without click?
with selenium:using click()
Ans:driver.click();
without click()
Ans: driver.findelement(By.id("button")).sendkeys(keys.ENTER);
(or)
without selenium:
Ans:No answer
Ans: driver.findelement(By.id("button")).sendkeys(keys.ENTER);
(or)
driver.findelement(By.id("button")).sendkeys(keys.RETURN);
Ans:No answer
18.write a script to click checkbox?with click() method ,without click() method?
with selenium:
with click()
Ans:driver.click():
without click()
Ans: driver.findelement(By.id("button")).sendkeys(keys.SPACE);
Ans: driver.findelement(By.id("button")).sendkeys(keys.SPACE);
or
Ans:driver.findelement(By.id("button")).sendkeys(" ");
without selenium:
Ans:No answer
19.write a script copy text present in textbox to another textbox?
with selenium:
Ans:driver.findElement(By.xpath("//span[text()='Contact Us']")).sendKeys("admin");String t = driver.findElement(By.xpath("//span[text()='Contact Us']")).
getAttribute("value");
System.out.println(t);
without selenium:
Ans:No answer
20.How to verify checkbox is selected or not?
with selenium:
Ans: boolean t = driver.findElement(By.xpath("//span[text()='Contact Us']")).isSelected();
System.out.println(t);
without selenium:
Ans:No answer
21.write a script to count no of options present in the listbox?
Ans:using getoptions()
WebElement t=driver.findElement(By.id("under_ststyy"));Select s=new Select(t);
List<WebElement> po = s.getOptions();
System.out.println(po);
for(int i=0;i<po.size();i++)
{
System.out.println(po.get(i).getText());
}
other way:using xpath
Ans:
List<WebElement> t = driver.findElements(By.xpath("//span[text()='Contact Us']/option"));
System.out.println(t);
for(int i=0;i<t.size();i++)
{
System.out.println(t.get(i).getText());
}
22.to print all option in list box in reverse order?
Ans:List<WebElement> po = s.getOptions();
System.out.println(po);
for(int ;i<po.size()-1;i>=0; i--)
{
System.out.println(po.get(i).getText());
}
23.write a script to search specified options present in list box?
Ans:List<WebElement> po = s.getOptions();
System.out.println(po);
for(int i=0;i<po.size();i++)
{
String v = po.get(i).getText());
if(v.contains("pak"))
{
System.out.println(po);
}
}
24.write a script to verify whether options is sorted or not ?
Ans:Select s=new Select(element);
List<WebElement> po = s.getOptions();
System.out.println(po);
String msg="sorted";
for(int i=0;i<po.size()-1;i++)
{
String s1 = po.get(i).getText();
String s2 = po.get(i+1).getText();
if(s1.compareTo(s2)>0)
{
msg="Not Sorted";
}
}
System.out.println(msg);
{
msg="Not Sorted";
}
}
System.out.println(msg);
25.write a script to count no of cells present each row of the webtable?
ROW:
Ans://row count
List<WebElement> t = driver.findElements(By.xpath("//tr"));
System.out.println(t.size());
Ans://row getext
List<WebElement> t = driver.findElements(By.xpath("//tr"));
System.out.println(t.size());
for(int i=0;i<t.size();i++)
{
String s1 = t.get(i).getText();
System.out.println(s1);
}
Column:
Ans://column count
List<WebElement> t = driver.findElements(By.xpath("//td"));
System.out.println(t.size());
Ans://coloumn getext
List<WebElement> t = driver.findElements(By.xpath("//td"));
System.out.println(t.size());
for(int i=0;i<t.size();i++)
{
String s1 = t.get(i).getText();
System.out.println(s1);
}
}
26.how to know whether page is fully loaded?
without selenium:
Ans: JavascriptExecutor js=(JavascriptExecutor) driver;
String name=(String) js.executeScript("alert(document.readtstate");
System.out.println(name);