Webdriver is not able to find element under subclass - selenium

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"));

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.

Selenium: How to click on href link when it wont have absolute path

I am trying to identify a link in the CQ5 webpage and click on it.
Below is the html code:
<a href="/siteadmin" title="Websites">
<div class="icon siteadmin">
<div class="title">Websites</div>
<div class="description">Create and manage multiple websites.
</div>
</div>
</a>
The below are method i tried to find the information and click on it.
driver.findElement(By.linkText("Websites")).click();
driver.findElement(By.xpath("//a[#href='/siteadmin']")).click();
Getting following exception:
Exception in thread "main" org.openqa.selenium.WebDriverException: unknown error: Element is not clickable at point (528, 174). Other element would receive the click: <div class="resourcebox">...</div>
(Session info: chrome=52.0.2743.116)
(Driver info: chromedriver=2.22.397933 (1cab651507b88dec79b2b2a22d1943c01833cc1b),platform=Windows NT 6.1.7601 SP1 x86_64) (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 39 milliseconds
Build info: version: '2.53.1', revision: 'a36b8b1', time: '2016-06-30 17:32:46'
System info: host: 'pilapwin7020', ip: '10.116.252.187', os.name: 'Windows 7', os.arch: 'amd64', os.version: '6.1', java.version: '1.8.0_101'
Driver info: org.openqa.selenium.chrome.ChromeDriver
Capabilities [{applicationCacheEnabled=false, rotatable=false, mobileEmulationEnabled=false, chrome={chromedriverVersion=2.22.397933 (1cab651507b88dec79b2b2a22d1943c01833cc1b), userDataDir=C:\Users\User\AppData\Local\Temp\scoped_dir44444_30971}, takesHeapSnapshot=true, databaseEnabled=false, handlesAlerts=true, hasTouchScreen=false, version=52.0.2743.116, platform=XP, browserConnectionEnabled=false, nativeEvents=true, acceptSslCerts=true, locationContextEnabled=true, webStorageEnabled=true, browserName=chrome, takesScreenshot=true, javascriptEnabled=true, cssSelectorsEnabled=true}]
Session ID: 5116ba44126c39293ac466aed3d6608a
You should try using JavascriptExecutor to perform click in this case as :-
((JavascriptExecutor)driver).executeScript("arguments[0].click()", driver.findElement(By.cssSelector("a[href = '/siteadmin'][title = 'Websites']")));
You need to check if the attr contains the string, because it returns the fullpath even if in the HTML shows only /siteadmin.
XPath Solution:
//a[contains(#href, '/siteadmin') and #title='Websites']
Css Selector Solution:
a[href*='/siteadmin'][title='Websites']

Selenium WebDriver: Unable to Select Element

<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

Selenium Webdriver | Unable to locate 'href' element

I am trying to locate below link in Selenium Webdriver using Xpath and CSS.
<table width="100%" cellspacing="0" cellpadding="0" border="0">
<tbody>
<tr>
<tr>
<td class="cspbItmA">
<a class="cspbItm" target="_parent" href="../isp_track.asp?PARENT_MENU=Customer Order">Find Order</a>
</td>
</tr>
But neither of these options, I am unable to run the script and trapped with below exception:
driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
driver.findElement(By.xpath(".//*[#id='cspbGrp0']/table/tbody/tr[2]/td/a")) .click();
Starting ChromeDriver (v2.9.248315) on port 8139 Exception in thread
"main" org.openqa.selenium.NoSuchElementException: no such element
(Session info: chrome=40.0.2214.115) (Driver info:
chromedriver=2.9.248315,platform=Windows NT 6.1 SP1 x86) (WARNING: The
server did not provide any stacktrace information) Command duration or
timeout: 5.06 seconds For documentation on this error, please visit:
http://seleniumhq.org/exceptions/no_such_element.html Build info:
version: '2.42.0', revision:
'5e824302019c86eae9c8c3ca9155e7307b410cf8', time: '2014-05-24
09:48:41' System info: host: 'inl-279930-1', ip: '10.13.174.254',
os.name: 'Windows 7', os.arch: 'x86', os.version: '6.1', java.version:
'1.7.0_55' Session ID: 04489825ed0cfc399afa1ffccb838870 Driver info:
org.openqa.selenium.chrome.ChromeDriver Capabilities [{platform=XP,
acceptSslCerts=true, javascriptEnabled=true, browserName=chrome,
chrome={userDataDir=C:\Users\SUBRAM~1\AppData\Local\Temp\scoped_dir11808_15574},
rotatable=false, locationContextEnabled=true, version=40.0.2214.115,
takesHeapSnapshot=true, cssSelectorsEnabled=true,
databaseEnabled=false, handlesAlerts=true,
browserConnectionEnabled=false, nativeEvents=true,
webStorageEnabled=true, applicationCacheEnabled=false,
takesScreenshot=true}] at
sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at
sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
at
sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:526)
at
org.openqa.selenium.remote.ErrorHandler.createThrowable(ErrorHandler.java:193)
at
org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:145)
at
org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:596)
at
org.openqa.selenium.remote.RemoteWebDriver.findElement(RemoteWebDriver.java:349)
at
org.openqa.selenium.remote.RemoteWebDriver.findElementByXPath(RemoteWebDriver.java:446)
at org.openqa.selenium.By$ByXPath.findElement(By.java:357) at
org.openqa.selenium.remote.RemoteWebDriver.findElement(RemoteWebDriver.java:341)
at roll_forward_test.cpe_progression.main(cpe_progression.java:147)
Could you help me to get this fixed, please.
My preference would be to use css over xpath and I would usually write my own selectors. Because it's in a table it can be a little tricky (meaning you may have to traverse from further up) but from the information on screen I'd go for something like:
//by href
driver.findElement(By.cssSelector("a[href='../isp_track.asp?PARENT_MENU=Customer Order']"))
OR
//by class
driver.findElement(By.cssSelector("a.cspbItm"))
Issue identified and it is caused due to the element present inside an iFrame.
When switching to iFrame first, now able to locate the element.
Thank You,
Praveen