Showing posts with label software testing jobs. Show all posts
Showing posts with label software testing jobs. Show all posts

Thursday, 14 May 2015

Delete Cookies in Selenium Webdriver API



Delete Cookies in Selenium Webdriver API
.i).Delete Cookie
ii).Delete Cookie with Name
iii).Delete All Cookies
Automation tester can delete a cookie from the browser "cookie jar". Domain of the cookie will be ignored.
Automation tester can delete the named cookie from the current domain. It is an equivalent to setting the named cookie's expiry date to sometime in the past.
Automation tester can also delete all the cookies for the current domain using driver.manage().deleteAllCookies();syntax.
ie:
Deleting the particular cookie with cookie name "--utmbTest"
@Test
public void deleteCookieNamedExampleTest()
{
driver= new FirefoxDriver();
String URL="http://www.flipcart.com";// User your own site
driver.navigate().to(URL);
driver.manage().deleteCookieNamed("__utmbTest");
}
Deleting all the cookies of the particular domain
@Test
public void deleteAllCookiesExample()
{
driver= new FirefoxDriver();
String URL="http://www.flipcart.com";
driver.navigate().to(URL);
driver.manage().deleteAllCookies();
}

Tuesday, 12 May 2015

SeleniumWebdriverException throws by selenium webdriver API Element is not clickable at point



SeleniumWebdriverException issue is occur only when working with chrome driver as the chrome browser uses the point location. When the element position is not fixed and we are trying to perform some action on that particular element will effect/result an error as 'selenium.common.exceptions.WebDriverException - Element is not clickable at point (12, 585). Other element would receive the click'.
This thing happens when the element is loaded into the DOM(document object model) but position is not fixed on the GUI. There may be some div,images or ads that are not being loaded completely and ChromeDriver always tries to click the middle of the particular element.
In this case work around that worked to resolve the given issue. But to make sure that the best and simple solution is to figure out the exact reason and how to fix the problem. We need to find out which part of the div and image is taking more time to download. Before clicking of an element we need to make sure that element is present in the DOM, visible in the GUI and the last and most  is position is fixed. When the element position is fixed then the problem is being solved. If you want to tweak that, try with Thread.sleep or verify in to the debug mode in eclapse.
Using Thread.sleep is not a good idea. Instead we need to go for WebDriverWait ExpectedConditions.
There are many Conditions that can be use within Webdriver tests.
a. visibilityOf(WebElement element) : An expectation for check that particular element, known to be exists on the DOM of a page, is visible.
b. visibilityOfElementLocated(By locator) : An expectation for check that an element is exists on the DOM of a page and its visibility.
In the above two conditions we are waiting for an element to be exist on the DOM of a web page and also its visible. These work fine only when the element is being loaded completely.
If the element is being loaded and visible. In chrome driver the position of the element is also necessary. Point to be noted that will work perfectly on Firefox driver.
Then question is how to resolved this problem in Chrome browser? Please check the number of comments and discussions on Chrome Element is not clickable issue blog
Below are the different cases that works for people who also face the same type of problem.
1. This is a simple solution that worked for most of the people. Try to maximize chrome browser when you are working with resolutions greater than 1024x768.
 
driver.manage().window().maximize();//maximize the browser
2. The second solution which also work for few user using through Actions Class
WebElement element = driver.findElement(By("element"));
Actions action = new Actions(driver);
action.moveToElement(element).click().perform();
3. Work for some user using JavaScriptExecutor. Make sure to import below org.openqa.selenium.JavascriptExecutor;
JavascriptExecutor js = (JavascriptExecutor)driver;
 // if element is on top.
js.executeScript("scroll(250, 0)");
//Element is on bottom.
js.executeScript("scroll(0, 250)");
4. It may be also try the below using X or Y position for points
        WebElement element = driver.findElement(By.id(""));
        JavascriptExecutor js =(JavascriptExecutor)driver;
        js.executeScript("window.scrollTo(0,"element.getLocation().y+")");// set position
        element.click();
Or
        WebElement element = driver.findElement(By.id(""));
        JavascriptExecutor js =(JavascriptExecutor)driver;
        js.executeScript("window.scrollTo(0,"element.getLocation().y+")");// set position
        element.click();

Monday, 11 May 2015

Example of Navigation Methods in Web driver API



Example of Navigation Methods in Web driver API
Navigate.To(URL)
Method/Function Name: navigate.to(URL)
Syntax: driver.navigate().to(URL);
Uses: Navigate To is a   method for loading a new web page in the current browser(FF,ie…so on) window. This action have done using a HTTP GET operation, and the method will block the next execution until the load is complete.
Parameters: URL – Should be fully qualified URL like http://silenumnmisc.blogspot.in/
 “ie”:-
@Test
private void navigationToURLIestMeethod()
{
driver= new FirefoxDriver();
driver.navigate().to("http://silenumnmisc.blogspot.in/");
}
Navigate.To(String)
Method or Function Name: navigate.to(String)
Syntax: driver.navigate().to(String);
Uses: navigate() function or methods load a new web page in the current browser window like FF, ie, Safari….this is a overloaded version of to(String) that makes it easy to pass in to this URL(http://silenumnmisc.blogspot.in/).
Parameters example: URL String
 “ie”:-
 @Test
private void navigationToStringIeTestMethod()
{
driver= new FirefoxDriver();
driver.navigate().to(URL);
}
Navigate.Back() Method
Method Name/Function : navigate().back()
Syntax: driver.navigate().back();
Uses: It is used for to move back a single "item" in the web browser history and it will not perform any action if you are on the first page viewed like no previous maintained by browser.
Parameters: not applicable
 “ie”:-
@Test
private void navigationBackIeMethod()
{
driver= new FirefoxDriver();
driver.navigate().to(URL);
driver.findElement(By.linkText("Forgot your password?")).click();
//Below is the statement to return in to back stage
driver.navigate().back();
}
In the above ie, while working with navigate back method, we need to travel to one single page in the browser history(to maintain browser history).
We have opened the first page is facebook.com page and then traveling to forgot password page. Currently the browser has two pages maintain in the history. If we currently use navigate.back() method, it will redirect the user to facebook.com page.
Navigate.Forward()
Method Name/Function: navigate().forward()
Syntax: driver.navigate().forward();
Uses: Moveing a single "item" forward in the web browser history and it won’t perform any action if we are in the latest page viewed.
Parameters: Not applicable
 “ie”
@Test
private void navigationForwardIe()
 {
driver= new FirefoxDriver();
driver.navigate().to(URL);
driver.findElement(By.linkText("Forgot your password?")).click();
driver.navigate().back();
driver.navigate().forward();
}
In the above ie, while work with navigate forward method, we require to travel to one or more pages in the browser history.
Initially first page we have opened is facebook.com page and then traveled to forget password page. Currently the browser has two pages in the history. If we now use navigate.back method, it will redirect the particular user to facebook.com page and now again if we use navigate.forward(), it will redirect the user to forgot password page.
Navigate.Refresh()
Method Name: navigate().refresh()
Syntax: driver.navigate().refresh();
Uses: It will refreshe the current web page
Parameters: Not Applicable
 “ie”:-
@Test
private void navigationRefreshIeMethod()
{
driver= new FirefoxDriver();
driver.navigate().to(URL);
driver.findElement(By.linkText("Forgot your password?")).click();
driver.findElement(By.id("identify_email")).sendKeys("abc@email.com");
driver.navigate().refresh();
}
Below is the sample script to perform page refresh using Action Driver class
@Test
private void testRefreshPage() {
driver= new FirefoxDriver();
driver.navigate().to("http://silenumnmisc.blogspot.in/");
Actions actions = new Actions(driver);
actions.keyDown(Keys.CONTROL).sendKeys(Keys.F5).perform();
}
Only some scenario where we eager need to check if the data is getting cleared once when the page refreshes and for few websites, it will show an alert when the user tries to refresh the page without saving the form which user has submitted data.
In the above ie, we are now refreshing the web page under test after entering the values using sendkeys() function.