Friday, March 30, 2012

Common error in your Dialy Usage of selenium

Error Codes in Selenium:
The WebDriver API indicates the success or failure of a command invocation via a status code on the Responseobject. The following values are used and have the following meanings.
Status Code Summary Detail
0 Success The command executed successfully.
7 NoSuchElement An element could not be located on the page using the given search parameters.
8 NoSuchFrame A request to switch to a frame could not be satisfied because the frame could not be found.
9 UnknownCommand The requested resource could not be found, or a request was received using an HTTP method that is not supported by the mapped resource.
10 StaleElementReference An element command failed because the referenced element is no longer attached to the DOM.
11 ElementNotVisible An element command could not be completed because the element is not visible on the page.
12 InvalidElementState An element command could not be completed because the element is in an invalid state (e.g. attempting to click a disabled element).
13 UnknownError An unknown server-side error occurred while processing the command.
15 ElementIsNotSelectable An attempt was made to select an element that cannot be selected.
17 JavaScriptError An error occurred while executing user supplied !JavaScript.
19 XPathLookupError An error occurred while searching for an element by XPath.
21 Timeout An operation did not complete before its timeout expired.
23 NoSuchWindow A request to switch to a different window could not be satisfied because the window could not be found.
24 InvalidCookieDomain An illegal attempt was made to set a cookie under a different domain than the current page.
25 UnableToSetCookie A request to set a cookie's value could not be satisfied.
26 UnexpectedAlertOpen A modal dialog was open, blocking this operation
27 NoAlertOpenError An attempt was made to operate on a modal dialog when one was not open.
28 ScriptTimeout A script did not complete before its timeout expired.
29 InvalidElementCoordinates The coordinates provided to an interactions operation are invalid.
30 IMENotAvailable IME was not available.
31 IMEEngineActivationFailed An IME engine could not be started.
32 InvalidSelector Argument was an invalid selector (e.g. XPath/CSS).

some of the Common Problems solutions given in selenium FQA's . I am not going to repete those ones. have look below link

http://code.google.com/p/selenium/w/list

Chrome: not clickable:-
------------------------

ChromeDriver always clicks the middle of the element in attempt to be faithful to what an actual user does. However, if you open Chrome and navigate to http://www.freelancersunion.org/about/index.html, you'll notice the link '1990s' is not clickable in the middle.
There are two ways to handle this currently:
1) Change/fix the page so that the user can click on the link in the middle.
2) Use the advanced user interactions API to click at the appropriate place in the link. e.g.,
ActionChains(w).move_to_element_with_offset(link, 0, 20).click().perform()

I suppose most of the 'Element is not clickable at point' errors are due to the link not actually being clickable in its middle. To check, open Chrome's developer tools via Inspect Element and hover over the element that is being clicked. Check that the middle of the bounding box that appears is actually clickable.
 
Solution:-
I guess the issue with clicking element may have something to do with element is not in the current view. For my case, following code makes it work

if u dont want to change everytime code . you will go with below one:
 
Capabilities cp = ((RemoteWebDriver) driver).getCapabilities();
if (cp.getBrowserName().equals("chrome")) 
{
try {
((JavascriptExecutor) driver).executeScript("arguments[0].scrollIntoView(true);", 
 webElement);
    } catch (Exception e) {  }
}

 webElement.click();

otherwise your doing in single browser just use:

WebElelement we=driver.findElement(By.xpath(""));
we.click;



2 comments: