1. Difference between Absolute path & Relative path.
Absolute path will start with root path (/) and Relative path will from current path (//)
7. Which is the best way to locate an element?
Finding elements by ID is usually going to be the fastest option, because at its root, it eventually calls down to document.getElementById(), which is optimized by many browsers.
Finding elements by XPath is useful for finding elements using very complex selectors, and is the most flexible selection strategy, but it has the potential to be very slow, particularly in IE. In IE 6, 7, or 8, finding by XPath can be an order of magnitude slower than doing the same in Firefox. IE provides no native XPath-over-HTML solution, so the project must use a JavaScript XPath implementation, and the JavaScript engine in legacy versions of IE really is that much slower.
If you have a need to find an element using a complex selector, I usually recommend using CSS Selectors, if possible. It's not quite as flexible as XPath, but will cover many of the same cases, without exhibiting the extreme performance penalty on IE that XPath can.
8. Why we refer Firefox driver to the web driver
inheritance.
inheritance.
webDriver driver = new FireFoxDriver();
WebDriver is an interface which contain several abstract methods such as get(...), findElamentBy(...) etc.
We simply create reference of web Driver and we can assign objects (Firefox driver, CromeDriver, IEDriver, Andriod driver etc) to it.
driver = new FireFoxDriver();
driver = new ChromeDriver();
by creating driver reference we avoid creatign multiple objects.
10. What is the difference between thread.Sleep() and selenium. Set Speed ("2000")?
If the application is taking time to load the page then we use selenium.waitforpageload(" "). This command is doesn’t wait upto the given time whenever the page load is completed.
If the application is taking time to refresh the page, then we use Thread. Sleep ( ).it is a standard wait it simply wait to the given time.
11. What is the difference between "GET" and "NAVIGATE" to open a web page in selenium
web driver?
Get method will get a page to load or get page source or get text that's all whereas navigate
will guide through back, forward.For example if we want to move forward and do some functionality and back to the home page this can be achieved through navigate() only. driver.get will wait till the whole page gets loaded and driver.navigate will just redirect to that page and will not wait
will guide through back, forward.For example if we want to move forward and do some functionality and back to the home page this can be achieved through navigate() only. driver.get will wait till the whole page gets loaded and driver.navigate will just redirect to that page and will not wait
12. In what situation selenium finding element fails?
- · Element loading issue
- · Dynamic id of web element
13. Please tell me the difference b/w implicitly Wait and Explicit wait.
Implicit Wait sets internally a timeout that will be used for all consecutive Web Element searches. It will try lookup the element again and again for the specified amount of time before throwing a NoSuchElementException if the element could not have been found. It does only this and can't be forced into anything else - it waits for elements to show up.
Explicit Wait or just Wait is a one-timer used by you for a particular search. It is more extendible in the means that you can set it up to wait for any condition you might like. Usually, you can use some of the prebuilt Expected Conditions to wait for elements to become clickable, visible, invisible, etc., or just write your own condition that suits your needs.
Example :
4. How we can retrieve the dynamically changing
Ids? When we login Facebook the login label's id
changes dynamically thus resulting in failure.
Ids? When we login Facebook the login label's id
changes dynamically thus resulting in failure.
We have a hierarchy of locators and Facebook Is dynamic in nature,so we are not able to
use "id" for identification for after that we have remaining 7 locator's for that :2. xpath ()..
3. name..4. css.. 5. link text.. 6. partiallinktext...7.tag name. so u can use any one for
identifying it. Most probably u can use "xpath" or "css-locator" and if there r tag then
link text or partial-link text. it depend on u . But we never use id's in Ajax application
because it’s not possible.
use "id" for identification for after that we have remaining 7 locator's for that :2. xpath ()..
3. name..4. css.. 5. link text.. 6. partiallinktext...7.tag name. so u can use any one for
identifying it. Most probably u can use "xpath" or "css-locator" and if there r tag then
link text or partial-link text. it depend on u . But we never use id's in Ajax application
because it’s not possible.
5.What is the difference between driver.Close()
and driver.Quit () method?
Close() - It is used to close the browser or page currently which is having the focus.
Quit() - It is used to shut down the web driver instance or destroy the web driver instance
(Close all the windows)
(Close all the windows)
16. How to scroll web element?--not browser—
FirefoxProfile profile=new FirefoxProfile();
profile.setEnableNativeEvents(true);
WebDriver driver=new FirefoxDriver(profile);
driver.navigate("http://jqueryui.com/draggable/");
Thread.sleep(6000L);
WebElement element=driver.findElement(By.xpath("//div[@id='draggable']"));
Actions actn=new Actions(driver);
actn.dragAndDropBy(element, 50, 50).build().perform();
}
17. What is the basic use of Firefox profiles and how can we use them using selenium?
A profile in Firefox is a collection of bookmarks, browser settings, extensions, passwords,
and history; in short, all of your personal settings.
and history; in short, all of your personal settings.
We use them to change user agent, changing default download directory, changing versions etc.
18. Customize the name of file going to be downloaded?
You have to download AUTO IT.exe file and has to be install
and later you have create .au3 file (in this file you have to specify the commands in
VB script like your file name, where have to save, it will be easy may be 3 or 4 steps )
using AUTOIT...then right click the .au3 file you have to compile ....after that you will
get the .exe file with the name of .au3 file ..In eclipse you will give the code like this
VB script like your file name, where have to save, it will be easy may be 3 or 4 steps )
using AUTOIT...then right click the .au3 file you have to compile ....after that you will
get the .exe file with the name of .au3 file ..In eclipse you will give the code like this
<----ProcessBuildder ps = new ProcessBuilder("path of the .exe file of au3") .start();--->
19. How to handle internationalisation through web driver?
FirefoxProfile profile = new FirefoxProfile();
profile.setPreference("intl.accept_languages","jp");
Web driver driver = new FirefoxDriver(profile);
driver.get(google.com) will open google in
Japanese Lang
Japanese Lang
20. How to overcome same origin policy through web driver?
- Proxy server.
DesiredCapabilities capability=new DesiredCapabilities.firefox();
capability.setCapability(CapabilityType.PROXY,"your desire proxy")
WebDriver driver=new FirefoxDriver(capability);
Reasearch more ......
21. How to put text in Facebook search box using
selenium web driver.
selenium web driver.
- · driver.findElement(By.xpath("//div[contains(@class, '_586i')]")).sendKeys("abc");
24. How can we get the font size, font color,
font type used for a particular text on a web
page using Selenium web driver?
font type used for a particular text on a web
page using Selenium web driver?
driver.findelement(By.Xpath("Xpath ").getcssvalue("font-size);
driver.findelement(By.Xpath("Xpath ").getcssvalue("font-colour);
driver.findelement(By.Xpath("Xpath ").getcssvalue("font-type);
driver.findelement(By.Xpath("Xpath ").getcssvalue("background-colour);
29. Is it possible test web services using selenium?
Using Jmeter we can test how one website is talking to each other means time taken to
send data, feeds, messages from one website to other website. Jmeter does a nice job
of doubling for performance and api tests.
send data, feeds, messages from one website to other website. Jmeter does a nice job
of doubling for performance and api tests.
30. How to refresh a page without using context
click?
click?
1.Using sendKeys.Keys method
2.Using navigate.refresh() method
3.Using navigate.refresh() method
4.Using get() method
5.Using sendKeys() method
1.Using sendKeys.Keys method
driver.get("https://accounts.google.com/SignUp");
driver.findElement(By.id("firstname-placeholder")).sendKeys(Keys.F5);
2.Using navigate.refresh() method
driver.get("http://ruchi-myseleniumblog.blogspot.in/2013/12/100-selenium-interview-questions.html");
driver.navigate().refresh();
3.Using navigate.to() method
driver.get("http://ruchi-myseleniumblog.blogspot.in/2014/01/selenium-hybrid-framework-using.html");
driver.navigate().to(driver.getCurrentUrl());
4.Using get() method
driver.get("http://ruchi-myseleniumblog.blogspot.in/2013/12/basic-core-java-interview-questions.html");
driver.get(driver.getCurrentUrl());
5.Using sendKeys() method
driver.get("https://accounts.google.com/SignUp");
driver.findElement(By.id("firstname-placeholder")).sendKeys("\uE035");
31. Can u send a code for printing in selenium?
There are two cases:
Case1. Any hyperlink/button on a web page, n clicking that link/button a print dialog box
opens. (Performing an action on web page)
opens. (Performing an action on web page)
Case2.or do u want to open print dialog box within ur own script, not by performing any
action on web page.
action on web page.
So If Case 1: just a call for WebElement.click() event will work to open it.
If Case 2: Call a Printer Job object (Use Awt API).
For code: Google it.
32. How to find broken images in a page using
Selenium Web driver.
Selenium Web driver.
1. Get xpath and then using tag name; get all the links in the page
2. Click on each and every link in the page
3. In the target page title, look for 404/500 error.
package programs;
import java.util.List;
import org.apache.http.HttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.DefaultHttpClient;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
public class findbrokenimages {
static int invalidimg;
static WebDriver driver ;
public static void main(String[] args) {
try {
driver = new FirefoxDriver();
driver.get("http://ruchi-myseleniumblog.blogspot.in");
invalidimg = 0;
List allImages = driver.findElements(By.tagName("img"));
System.out.println("Total images are " + allImages.size());
for (int i = 0; i < allImages.size(); i++) {
WebElement img = (WebElement) allImages.get(i);
if (img != null) {
verifyimgActive(img);
}
}
System.out.println("Total invalid images are " + invalidimg);
driver.quit();
} catch (Exception e) {
e.printStackTrace();
System.out.println(e.getMessage());
}
}
public static void verifyimgActive(WebElement img) {
try {
HttpResponse response = new DefaultHttpClient().execute(new HttpGet(img.getAttribute("src")));
if (response.getStatusLine().getStatusCode() != 200)
invalidimg++;
}
catch (Exception e) {
e.printStackTrace();
}
}
}
import java.util.List;
import org.apache.http.HttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.DefaultHttpClient;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
public class findbrokenimages {
static int invalidimg;
static WebDriver driver ;
public static void main(String[] args) {
try {
driver = new FirefoxDriver();
driver.get("http://ruchi-myseleniumblog.blogspot.in");
invalidimg = 0;
List allImages = driver.findElements(By.tagName("img"));
System.out.println("Total images are " + allImages.size());
for (int i = 0; i < allImages.size(); i++) {
WebElement img = (WebElement) allImages.get(i);
if (img != null) {
verifyimgActive(img);
}
}
System.out.println("Total invalid images are " + invalidimg);
driver.quit();
} catch (Exception e) {
e.printStackTrace();
System.out.println(e.getMessage());
}
}
public static void verifyimgActive(WebElement img) {
try {
HttpResponse response = new DefaultHttpClient().execute(new HttpGet(img.getAttribute("src")));
if (response.getStatusLine().getStatusCode() != 200)
invalidimg++;
}
catch (Exception e) {
e.printStackTrace();
}
}
}
33. How to handle Ajax popup window?
By using getWindowHandles() and obj.switchTo.window(windowid) we can handle popups using
explicit wait and driver.swtchT0.window("name") commands for your requirements.
explicit wait and driver.swtchT0.window("name") commands for your requirements.
34. How to handle auto complete box in web driver?
How to handle autocomplete box in web driver?
driver.findElement(By.id("your searchBox")).sendKeys("your partial keyword");
Thread.sleep(3000);
List <WebElement> listItems = driver.findElements(By.xpath("your list item locator"));
listItems.get(0).click();
driver.findElement(By.id("your searchButton")).click();
35. How to get the name of browser using Web Driver?
public class JsExecute
{
WebDriver driver;
JavascriptExecutor js;
@Before
public void setUp() throws Exception
{
driver=new FirefoxDriver();
driver.get("http://www.google.com");
}
@Test
public void test()
{
JavascriptExecutor js = (JavascriptExecutor) driver;
System.out.println(js.executeScript("return navigator.appCodeName"));
}}
OR
String s = (String) ((JavascriptExecutor) driver).executeScript("return navigator.userAgent;");
System.out.println("Browser name : " + s);
36. How to handle colors in web driver?
Use getCssValue(arg0) function to get the colors by sending 'color' string as an argument.
Example
String col = driver.findElement(By.id(locator)).getCssValue("color");
38. How to get text from captcha image??
driver.findElement(By.xpath(".//*[@id='SkipCaptcha']")).click();
String attr = ie.findElement(By.xpath(".//*[@id='SkipCaptcha']")).getAttribute("value");
System.out.println("The value of the attribute 'Name' is " + attr);
39. Is there a way to click hidden LINK in web driver?
String Block1 = driver.findElement(By.id("element ID"));
JavascriptExecutor js1=(JavascriptExecutor)driver;
js1.executeScript("$("+Block1+").css({'display':'block'});");
40. What Class Extends Web Driver?
- · AndroidDriver, ChromeDriver, EventFiringWebDriver, FirefoxDriver, HtmlUnitDriver,
InternetExplorerDriver, IPhoneDriver, PhantomJSDriver, RemoteWebDriver, SafariDriver
41. What are the APIs that support Web Driver?
- API are nothing but collection of all selenium commands for Locating UI Elements
(WebElements),Fetching a Page,User Input etc…
42. How to disable cookies in browser.
- Using deleteAllVisibleCookies() in selenium
No comments:
Post a Comment