Selenium WebDriver: Unable to Select Element - selenium

<input type="text" id="mobile" name="mobile" placeholder="Mobile Number" maxlength="10" value="" onkeyup="javascript:dispLocMob(this);" onkeydown="javascript:dispLocMob(this);" onchange="javascript:dispLocMob(this);">
Shown above is the element that I'm trying to send keys. I tried by xpath and id and all sorts of selectors, but it throws an error that is shown below:
Unable to locate element: {"method":"xpath","selector":"/html/body/div[3]/div/form/div[2]/div[1]/input"}
Command duration or timeout: 338 milliseconds
For documentation on this error, please visit: http://seleniumhq.org/exceptions/no_such_element.html
Build info: version: '2.53.0', revision: '35ae25b', time: '2016-03-15 16:57:40'
System info: host: 'ClaimsCM8', ip: '192.168.110.118', os.name: 'Windows 8', os.arch: 'x86', os.version: '6.2', java.version: '1.7.0_51'
*** Element info: {Using=xpath, value=/html/body/div[3]/div/form/div[2]/div[1]/input}
Session ID: ec543fff-7116-4880-8c98-7c60a1c697d0
Driver info: org.openqa.selenium.firefox.FirefoxDriver
Capabilities [{platform=WINDOWS, acceptSslCerts=true, javascriptEnabled=true, cssSelectorsEnabled=true, databaseEnabled=true, browserName=firefox, handlesAlerts=true, nativeEvents=false, webStorageEnabled=true, rotatable=false, locationContextEnabled=true, applicationCacheEnabled=true, takesScreenshot=true, version=45.0.2}]
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
at org.openqa.selenium.remote.ErrorHandler.createThrowable(ErrorHandler.java:206)
at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:158)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:678)
at org.openqa.selenium.remote.RemoteWebDriver.findElement(RemoteWebDriver.java:363)
at org.openqa.selenium.remote.RemoteWebDriver.findElementByXPath(RemoteWebDriver.java:500)
at org.openqa.selenium.By$ByXPath.findElement(By.java:361)
at org.openqa.selenium.remote.RemoteWebDriver.findElement(RemoteWebDriver.java:355)
at Selenium.Test2.main(Test2.java:62)
Caused by: org.openqa.selenium.NoSuchElementException: Unable to locate element: {"method":"xpath","selector":"/html/body/div[3]/div/form/div[2]/div[1]/input"}
For documentation on this error, please visit: http://seleniumhq.org/exceptions/no_such_element.html
Build info: version: '2.53.0', revision: '35ae25b', time: '2016-03-15 16:57:40'
System info: host: 'ClaimsCM8', ip: '192.168.110.118', os.name: 'Windows 8', os.arch: 'x86', os.version: '6.2', java.version: '1.7.0_51'
Driver info: driver.version: unknown
at <anonymous class>.FirefoxDriver.prototype.findElementInternal_(file:///C:/Users/EFERNA~1/AppData/Local/Temp/anonymous4369679942726534324webdriver-profile/extensions/fxdriver#googlecode.com/components/driver-component.js:10770)
at <anonymous class>.FirefoxDriver.prototype.findElement(file:///C:/Users/EFERNA~1/AppData/Local/Temp/anonymous4369679942726534324webdriver-profile/extensions/fxdriver#googlecode.com/components/driver-component.js:10779)
at <anonymous class>.DelayedCommand.prototype.executeInternal_/h(file:///C:/Users/EFERNA~1/AppData/Local/Temp/anonymous4369679942726534324webdriver-profile/extensions/fxdriver#googlecode.com/components/command-processor.js:12661)
at <anonymous class>.DelayedCommand.prototype.executeInternal_(file:///C:/Users/EFERNA~1/AppData/Local/Temp/anonymous4369679942726534324webdriver-profile/extensions/fxdriver#googlecode.com/components/command-processor.js:12666)
at <anonymous class>.DelayedCommand.prototype.execute/<(file:///C:/Users/EFERNA~1/AppData/Local/Temp/anonymous4369679942726534324webdriver-profile/extensions/fxdriver#googlecode.com/components/command-processor.js:12608)
Is there something defined in the Web Element that does not let me access the element in my Selenium script?
Any suggestions/advice will be highly appreciated.
Thanks you!

Try as below :-
WebDriverWait wait = new WebDriverWait(driver, 10);
el = wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("mobile")));
el.sendKeys("your value");
Note :- Be ensure before finding element that it is not inside any frame or iframe. If it is inside any frame or iframe you need to switch that frame first as :- driver.switchTo().frame("frame name or id")
Hope it will help you...:)

First of all, If you are using xpaths then use relative xpath instead of absolute as slight change in DOM makes absolute xpaths invalid or refer to a wrong element.
Second try using .click(); before .sendkeys();. So your code can be something like
WebElement ele = dvr.findElement(By.id("mobile"));
ele.click();
ele.sendKeys("your string");
Lastly, make sure you do not have any duplicate elements on the page with same property, i.e. id=="mobile". Hope this helps

Please try below code:
If the element is not in any frame:
driver.findElement(By.id("mobile")).sendKeys("");
If the element is inside a frame:
// Switching to the frame
driver.switchTo().frame(<framename>);
driver.findElement(By.id("mobile")).sendKeys("");
driver.switchTo().defaultContent();
Also, please add some wait after launching the page and entering the text. And even if the code is not working, please check whether the element is visible or not using below code:
if(driver.findElement(By.id("mobile")).isDisplayed()) {
// Add the code given above
}
Hope this helps

Related

Selenium locator xpath not working for particular button

I'm looking for a working locator to address a button on a web page.
"Inspecting element" in the code I see :
<input class="ruButton ruBrowse" tabindex="-1" value="Select & Upload File" style="border: 0px dotted;" type="button">
Copying outerhtml I have :
<input tabindex="-1" value="Select & Upload File" class="ruButton ruBrowse" style="border: 0px dotted;" type="button">
I tried the following as xpath locators but these are not OK - I'd like to understand why :
//input[#value='Select & Upload File']
//input[#value='Select & Upload File']
This locator is OK :
driver.findElement(By.xpath("//input[contains(#class,'ruButton ruBrowse') and contains(#type,'button')]")).click();
More details on error log :
1)
driver.get(baseUrl);
driver.findElement(By.xpath("//input[contains(#value,'Select') and contains (#value,'Upload File')]")).click();
Exception in thread "main" org.openqa.selenium.NoSuchElementException: Unable to find element with xpath == //input[contains(#value,'Select') and contains(#value,'Upload File')] (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 297 milliseconds
For documentation on this error, please visit: http://seleniumhq.org/exceptions/no_such_element.html
Build info: version: 'unknown', revision: '1969d75', time: '2016-10-18 09:43:45 -0700'
System info: host: 'BGC-W7X64T-2082', ip: '10.119.137.75', os.name: 'Windows 7', os.arch: 'x86', os.version: '6.1', java.version: '1.8.0_112'
Driver info: org.openqa.selenium.ie.InternetExplorerDriver
Capabilities [{browserAttachTimeout=0, ie.enableFullPageScreenshot=true, enablePersistentHover=true, ie.forceCreateProcessApi=false, ie.forceShellWindowsApi=false, pageLoadStrategy=normal, ignoreZoomSetting=false, ie.fileUploadDialogTimeout=3000, version=11, platform=WINDOWS, nativeEvents=true, ie.ensureCleanSession=false, elementScrollBehavior=0, ie.browserCommandLineSwitches=, requireWindowFocus=false, browserName=internet explorer, initialBrowserUrl=http://localhost:2351/, javascriptEnabled=true, ignoreProtectedModeSettings=false, enableElementCacheCleanup=true, unexpectedAlertBehaviour=dismiss}]
Session ID: 4613c6bf-239c-4ccb-b3b3-f1946276e7c7
*** Element info: {Using=xpath, value=//input[contains(#value,'Select') and contains(#value,'Upload File')]}
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
at org.openqa.selenium.remote.ErrorHandler.createThrowable(ErrorHandler.java:216)
at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:168)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:635)
at org.openqa.selenium.remote.RemoteWebDriver.findElement(RemoteWebDriver.java:368)
at org.openqa.selenium.remote.RemoteWebDriver.findElementByXPath(RemoteWebDriver.java:473)
at org.openqa.selenium.By$ByXPath.findElement(By.java:361)
at org.openqa.selenium.remote.RemoteWebDriver.findElement(RemoteWebDriver.java:360)
at Selenium_And_AutoIt.main(Selenium_And_AutoIt.java:61)
2)
driver.get(baseUrl);
driver.findElement(By.xpath("//input[#value='Select & Upload File']")).click();
Exception in thread "main" org.openqa.selenium.NoSuchElementException: Unable to find element with xpath == //input[#value='Select & Upload File'] (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 281 milliseconds
For documentation on this error, please visit: http://seleniumhq.org/exceptions/no_such_element.html
Build info: version: 'unknown', revision: '1969d75', time: '2016-10-18 09:43:45 -0700'
System info: host: 'BGC-W7X64T-2082', ip: '10.119.137.75', os.name: 'Windows 7', os.arch: 'x86', os.version: '6.1', java.version: '1.8.0_112'
Driver info: org.openqa.selenium.ie.InternetExplorerDriver
Capabilities [{browserAttachTimeout=0, ie.enableFullPageScreenshot=true, enablePersistentHover=true, ie.forceCreateProcessApi=false, ie.forceShellWindowsApi=false, pageLoadStrategy=normal, ignoreZoomSetting=false, ie.fileUploadDialogTimeout=3000, version=11, platform=WINDOWS, nativeEvents=true, ie.ensureCleanSession=false, elementScrollBehavior=0, ie.browserCommandLineSwitches=, requireWindowFocus=false, browserName=internet explorer, initialBrowserUrl=http://localhost:21427/, javascriptEnabled=true, ignoreProtectedModeSettings=false, enableElementCacheCleanup=true, unexpectedAlertBehaviour=dismiss}]
Session ID: eb3f9de0-2fc1-41ce-8f15-6947f956c216
*** Element info: {Using=xpath, value=//input[#value='Select & Upload File']}
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
at org.openqa.selenium.remote.ErrorHandler.createThrowable(ErrorHandler.java:216)
at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:168)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:635)
at org.openqa.selenium.remote.RemoteWebDriver.findElement(RemoteWebDriver.java:368)
at org.openqa.selenium.remote.RemoteWebDriver.findElementByXPath(RemoteWebDriver.java:473)
at org.openqa.selenium.By$ByXPath.findElement(By.java:361)
at org.openqa.selenium.remote.RemoteWebDriver.findElement(RemoteWebDriver.java:360)
at Selenium_And_AutoIt.main(Selenium_And_AutoIt.java:60)
Thank you !
For what it's worth, I've had trouble in the past with using text that has ampersand(s) inside as well. My solution is to use contains instead of "=" and only provide part of the value text, however, this might not be sufficient since there could conceivably be some other element that contains "Upload File" for example. My solution in this case, assuming that the locator as-is is incorrect, would be the following locator:
//input[contains(#value,'Select') and contains(#value,'Upload File')]
it could also substitute the 'contains' with 'starts-with' and 'ends-with' correspondingly.

Not able to check 2nd checkbox. Getting org.openqa.selenium.WebDriverException: unknown error: Element is not clickable at point (106, 655)

I am getting WebDriverException while trying to select the 2nd checkbox in the list. I am able to select the 1st check box but on the 2nd time my code throwing exception. Please find the method that i am using and exception message below.
Note: Any suggestion will be helpful for me.
URL: https://www.snapdeal.com/products/computers-external-hard-drives?sort=plrty&q=Capacity_s%3A1%20TB%7C
public void capacitySelection(String capacity){
WebDriverWait wd = new WebDriverWait(driver, 180);
List<WebElement> cList = wd.until(ExpectedConditions.presenceOfAllElementsLocatedBy(By.xpath("//div[#data-name='Capacity_s']/div")));
int i=1;
for(WebElement we:cList){
WebElement select= wd.until(ExpectedConditions.presenceOfElementLocated(By.xpath("//div[#data-name='Capacity_s']/div["+ i++ +"]/label")));
if(select.getText().contains(capacity)){
select.click();
break;
}
}
}
Exception Message:
Exception in thread "main" org.openqa.selenium.WebDriverException: unknown error: Element is not clickable at point (106, 655). Other element would receive the click: <label for="Capacity_s-3TB">...</label>
(Session info: chrome=54.0.2840.99)
(Driver info: chromedriver=2.24.417431 (9aea000394714d2fbb20850021f6204f2256b9cf),platform=Windows NT 6.2.9200 x86_64) (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 86 milliseconds
Build info: version: 'unknown', revision: '1969d75', time: '2016-10-18 09:43:45 -0700'
System info: host: 'Bishnu', ip: '192.168.0.107', os.name: 'Windows 8', os.arch: 'amd64', os.version: '6.2', java.version: '1.8.0_111'
Driver info: org.openqa.selenium.chrome.ChromeDriver
Capabilities [{applicationCacheEnabled=false, rotatable=false, mobileEmulationEnabled=false, networkConnectionEnabled=false, chrome={chromedriverVersion=2.24.417431 (9aea000394714d2fbb20850021f6204f2256b9cf), userDataDir=C:\Users\Bishnu\AppData\Local\Temp\scoped_dir11044_5076}, takesHeapSnapshot=true, pageLoadStrategy=normal, databaseEnabled=false, handlesAlerts=true, hasTouchScreen=false, version=54.0.2840.99, platform=WIN8, browserConnectionEnabled=false, nativeEvents=true, acceptSslCerts=true, locationContextEnabled=true, webStorageEnabled=true, browserName=chrome, takesScreenshot=true, javascriptEnabled=true, cssSelectorsEnabled=true}]
Session ID: 505ec9fb429bc6b9806edb52d75856f0
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
at org.openqa.selenium.remote.ErrorHandler.createThrowable(ErrorHandler.java:216)
at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:168)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:635)
at org.openqa.selenium.remote.RemoteWebElement.execute(RemoteWebElement.java:274)
at org.openqa.selenium.remote.RemoteWebElement.click(RemoteWebElement.java:84)
at in.prolearn.pages.HomePage.SecondCapacitySelection(HomePage.java:59)
at in.prolearn.testcases.VerifySnapDealSelection.main(VerifySnapDealSelection.java:22)
Thanks.
Can you use JavaScript instead
WebElement product = new WebDriverWait(aDriverInstance, 5L).
until(ExpectedConditions.visibilityOfElementLocatedBy(By.id("anID")));
JavascriptExecutor jsExec = (JavascriptExecutor) aDriverInstance;
jsExec.executeScript("arguments[0].scrollIntoView()", product);
Actions actions = new Actions(driver);
actions.moveToElement(select).click().perform();
Try to click the element with Actions class. This will help you.
Use .isSelected() method before performing click on that element.

Element is not clickable - Error Getting while running Selenium testcases

I am getting following error while running selenium testcases.
Using the versions firefox 45 and selenium-server-standalone 2.52.
org.openqa.selenium.WebDriverException: Element is not clickable at
point (62, 13.333328247070312). Other element would receive the click:
(WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 21 milliseconds Build info: version:
'2.52.0', revision: '4c2593c', time: '2016-02-11 19:06:42' System
info: host:
'mesos-wl-servicetest-8f2fe7b6-d8bd-429f-abfc-cf5d29242b38', ip:
'172.31.6.249', os.name: 'Linux', os.arch: 'amd64', os.version:
'4.4.2-1.el7.elrepo.x86_64', java.version: '1.8.0_51' Driver info:
org.openqa.selenium.firefox.FirefoxDriver Capabilities
[{applicationCacheEnabled=true, rotatable=false,
pageLoadStrategy=fast, handlesAlerts=true, databaseEnabled=true,
version=45.1.0, platform=LINUX, nativeEvents=false,
acceptSslCerts=false, webStorageEnabled=true,
locationContextEnabled=true, browserName=firefox,
takesScreenshot=true, javascriptEnabled=true,
pageLoadingStrategy=fast, cssSelectorsEnabled=true}] Session ID:
d6ae5f7f-be19-4b79-b248-dfb034d6ce1c at
sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at
sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at
sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:422)
at
org.openqa.selenium.remote.ErrorHandler.createThrowable(ErrorHandler.java:206)
at
org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:158)
at
org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:678)
at
org.openqa.selenium.remote.RemoteExecuteMethod.execute(RemoteExecuteMethod.java:35)
at org.openqa.selenium.remote.RemoteMouse.click(RemoteMouse.java:59)
at
org.openqa.selenium.interactions.ClickAction.perform(ClickAction.java:37)
at
org.openqa.selenium.interactions.CompositeAction.perform(CompositeAction.java:50)
at org.openqa.selenium.interactions.Actions.perform(Actions.java:373)
You should try using JavascriptExecutor
WebElement el = driver.findElement....;
JavascriptExecutor executor = (JavascriptExecutor)driver
executor.executeScript("arguments[0].click()", el);
Hope it will help you to perform click...:)
JavascriptExecutor click is an good option to avoid element is not clickable at point (xx,yy). Other element would receive the click.
ANother alternate that you can use is explicit wait for presence of that element
Possible solutions can be ..
1)Try to maximize the browser when you are working with resolutions greater than 1024x768.
driver.manage().window().maximize();
2) Using Actions Class
WebElement element = driver.findElement(By("element"));
Actions action = new Actions(driver);
action.moveToElement(element).click().perform();
3) using JavaScriptExecutor
WebElement el = driver.findElement(By("element"));
JavascriptExecutor executor = (JavascriptExecutor)driver
executor.executeScript("arguments[0].click()", el);

Webdriver is not able to find element under subclass

I am trying to find element "core_text savable core_valid_regex" but everytime I am getting some or the other error.
<form id="core_order_holder" onsubmit="return false;">
<table class="order_holder">
<tbody class="core_loader_holder">
<tr>
<td class="core_item_label">Personal number:</td>
<td class="core_item_content">
<span class="savable-wrapper">
<input class="**core_text savable core_valid_regex**" type="text" name="loginid" size="13" style="outline: medium none;">
<span class="savable">
</span>
</td>
</tr>
Till now I have tried the following approaches:
WebElement PersonalNumber = (new WebDriverWait(driver, 30)) .until(ExpectedConditions.presenceOfElementLocated(By.className("order_holder"))).findElement(By.className("core_loader_holder")).findElement(By.className("core_item_content")).findElement(By.className("savable-wrapper")).findElement(By.className("core_text savable"));
WebElement E1 = PersonalNumber.findElement(By.className("core_loader_holder")).findElement(By.className("core_item_content"));
WebElement E2 = E1.findElement(By.className("core_item_content"));
WebElement E3 = E2.findElement(By.className("savable-wrapper"));
WebElement E4 = E3.findElement(By.className("core_text savable"));
WebElement PersonalNumber = driver.findElement(By.className("core_text savable"));
WebElement PersonalNumber = (new WebDriverWait(driver, 30))
.until(ExpectedConditions.presenceOfElementLocated(By.className("core_text savable")));
WebElement E1 = (new WebDriverWait(driver, 30)).until(ExpectedConditions.presenceOfAllElementsLocatedBy(PersonalNumber.findElement(By.className("core_loader_holder"))));
WebElement PersonalNumber = driver.findElement(By.className("order_holder") ).findElement(By.className("core_loader_holder")).findElement(By.className("core_item_content")).findElement(By.className("savable-wrapper")).findElement(By.name("loginid"));
Please find below the error:
Exception in thread "main" org.openqa.selenium.NoSuchElementException: Unable to locate element: {"method":"class name","selector":"core_item_content"}
Command duration or timeout: 82 milliseconds
For documentation on this error, please visit: http://seleniumhq.org/exceptions/no_such_element.html
Build info: version: '2.45.0', revision: '32a636c', time: '2015-03-05 22:01:35'
System info: host: 'PC239657', ip: '172.31.204.104', os.name: 'Windows 7', os.arch: 'x86', os.version: '6.1', java.version: '1.7.0'
*** Element info: {Using=class name, value=core_item_content}
Session ID: 1a8604de-4ec7-4a77-ba8b-b1590ae49ce6
Driver info: org.openqa.selenium.firefox.FirefoxDriver
Capabilities [{platform=WINDOWS, acceptSslCerts=true, javascriptEnabled=true, browserName=firefox, rotatable=false, locationContextEnabled=true, version=34.0.5, cssSelectorsEnabled=true, databaseEnabled=true, handlesAlerts=true, nativeEvents=true, webStorageEnabled=true, applicationCacheEnabled=true, takesScreenshot=true}]
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
at org.openqa.selenium.remote.ErrorHandler.createThrowable(ErrorHandler.java:204)
at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:156)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:599)
at org.openqa.selenium.remote.RemoteWebElement.execute(RemoteWebElement.java:268)
at org.openqa.selenium.remote.RemoteWebElement.findElement(RemoteWebElement.java:171)
at org.openqa.selenium.remote.RemoteWebElement.findElementByClassName(RemoteWebElement.java:228)
at org.openqa.selenium.By$ByClassName.findElement(By.java:387)
at org.openqa.selenium.remote.RemoteWebElement.findElement(RemoteWebElement.java:167)
at Submit_Order.TrustlySubmitOrder(Submit_Order.java:237)
at Submit_Order.main(Submit_Order.java:260)
Caused by: org.openqa.selenium.NoSuchElementException: Unable to locate element: {"method":"class name","selector":"core_item_content"}
For documentation on this error, please visit: http://seleniumhq.org/exceptions/no_such_element.html
Build info: version: '2.45.0', revision: '32a636c', time: '2015-03-05 22:01:35'
System info: host: 'PC239657', ip: '172.31.204.104', os.name: 'Windows 7', os.arch: 'x86', os.version: '6.1', java.version: '1.7.0'
Driver info: driver.version: unknown
at <anonymous class>.FirefoxDriver.prototype.findElementInternal_(file:///C:/Users/291578/AppData/Local/Temp/anonymous5858848057389913831webdriver-profile/extensions/fxdriver#googlecode.com/components/driver-component.js:10271)
at <anonymous class>.FirefoxDriver.prototype.findChildElement(file:///C:/Users/291578/AppData/Local/Temp/anonymous5858848057389913831webdriver-profile/extensions/fxdriver#googlecode.com/components/driver-component.js:10283)
at <anonymous class>.DelayedCommand.prototype.executeInternal_/h(file:///C:/Users/291578/AppData/Local/Temp/anonymous5858848057389913831webdriver-profile/extensions/fxdriver#googlecode.com/components/command-processor.js:12274)
at <anonymous class>.DelayedCommand.prototype.executeInternal_(file:///C:/Users/291578/AppData/Local/Temp/anonymous5858848057389913831webdriver-profile/extensions/fxdriver#googlecode.com/components/command-processor.js:12279)
at <anonymous class>.DelayedCommand.prototype.execute/<(file:///C:/Users/291578/AppData/Local/Temp/anonymous5858848057389913831webdriver-profile/extensions/fxdriver#googlecode.com/components/command-processor.js:12221)
How to find the element?
Is it always the only input element in the form? Does it always have the same name attribute?
In that case, you can simply try:
WebElement input = driver.findElement(By.Name("loginid"));
Or:
WebElement input = driver.findElement(By.CssSelector("#core_order_holder input"));

Query related to Explicit wait: wait.until(ExpectedConditions.visibilityOfElementLocated(By.id(

package wait1;
import org.openqa.selenium.By;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;
public class Explicit {
public static void main(String[] args) {
FirefoxDriver driver= new FirefoxDriver();
WebDriverWait wait= new WebDriverWait(driver,20 );
driver.get("http://www.91mobiles.com/");
driver.findElement(By.xpath("//*[#id='q']")).sendKeys("Micromax");
//wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//*[#id='ui-id-22']/span[2]")));
wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("id=ui-id-172")));
driver.findElement(By.xpath("//*[#id='ui-id-52']")).click();
}
}
I am getting the following error when I execute the above script:
Exception in thread "main" org.openqa.selenium.TimeoutException: Timed out after 20 seconds waiting for visibility of element located by By.id: id=ui-id-172
Build info: version: '2.33.0', revision: '4e90c97', time: '2013-05-22 15:33:32'
System info: os.name: 'Windows 7', os.arch: 'amd64', os.version: '6.1', java.version: '1.7.0_25'
Driver info: driver.version: unknown
at org.openqa.selenium.support.ui.FluentWait.timeoutException(FluentWait.java:259)
at org.openqa.selenium.support.ui.FluentWait.until(FluentWait.java:228)
at wait1.Explicit.main(Explicit.java:20)
Caused by: org.openqa.selenium.NoSuchElementException: Unable to locate element: {"method":"id","selector":"id=ui-id-172"}
Command duration or timeout: 21 milliseconds
For documentation on this error, please visit: http://seleniumhq.org/exceptions/no_such_element.html
Build info: version: '2.33.0', revision: '4e90c97', time: '2013-05-22 15:33:32'
System info: os.name: 'Windows 7', os.arch: 'amd64', os.version: '6.1', java.version: '1.7.0_25'
Session ID: fd977506-2457-4981-a304-f9a9b6b57f4e
Driver info: org.openqa.selenium.firefox.FirefoxDriver
Capabilities [{platform=XP, databaseEnabled=true, cssSelectorsEnabled=true, javascriptEnabled=true, acceptSslCerts=true, handlesAlerts=true, browserName=firefox, browserConnectionEnabled=true, nativeEvents=true, webStorageEnabled=true, rotatable=false, locationContextEnabled=true, applicationCacheEnabled=true, takesScreenshot=true, version=17.0.7}]
at sun.reflect.GeneratedConstructorAccessor10.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
at org.openqa.selenium.remote.ErrorHandler.createThrowable(ErrorHandler.java:191)
at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:145)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:554)
at org.openqa.selenium.remote.RemoteWebDriver.findElement(RemoteWebDriver.java:307)
at org.openqa.selenium.remote.RemoteWebDriver.findElementById(RemoteWebDriver.java:348)
at org.openqa.selenium.By$ById.findElement(By.java:216)
at org.openqa.selenium.remote.RemoteWebDriver.findElement(RemoteWebDriver.java:299)
at org.openqa.selenium.support.ui.ExpectedConditions.findElement(ExpectedConditions.java:522)
at org.openqa.selenium.support.ui.ExpectedConditions.access$0(ExpectedConditions.java:520)
at org.openqa.selenium.support.ui.ExpectedConditions$4.apply(ExpectedConditions.java:130)
at org.openqa.selenium.support.ui.ExpectedConditions$4.apply(ExpectedConditions.java:1)
at org.openqa.selenium.support.ui.FluentWait.until(FluentWait.java:208)
... 1 more
Caused by: org.openqa.selenium.remote.ErrorHandler$UnknownServerException: Unable to locate element: {"method":"id","selector":"id=ui-id-172"}
Build info: version: '2.33.0', revision: '4e90c97', time: '2013-05-22 15:33:32'
System info: os.name: 'Windows 7', os.arch: 'amd64', os.version: '6.1', java.version: '1.7.0_25'
Driver info: driver.version: unknown
The behavior you are getting is the expected bahavior. You specified a 20 second explicit wait and in that time the ExpectedConditions.visibilityOfElementLocated(...) could not be established. So the wait fails with a timeout.
If you want to go on in your program you need to surround the wait in a try-catch block and catch org.openqa.selenium.TimeoutException
Try using like this
wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//*[#id='ui-id-52']"));
Make sure that whatever identification type you use while waiting should be in the statement you use for action. (e.g. click, set etc.)
Here, we have two solutions...
Try increasing your WebDriverWait time to check if it fix the issue.
Try to locate same element by firebug, if it is successfully found by firebug, than WebDriverWait time is the only culprit.
You'll always get a timeout with the code you have. This is the offending line:
wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("id=ui-id-172")));
Note how you have By.id("id=ui-id-172"). This is wrong. It would look for an object that has the id id=ui-id-172. While it is possible to have an id with this value (yes, I tried and it works) it is unlikely that this is what you want, especially given your XPath expression on the next line. What you want, to be consistent with the rest of your code, is By.id("ui-id-172").