This question already has answers here:
Unable to locate an element using xpath error in selenium-java
(4 answers)
Closed 4 years ago.
This is the code I have written.
public WebDriver createPart() {
try {
driver.findElement(By.id("username")).sendKeys("502409373");
driver.findElement(By.id("password")).sendKeys("Magic14Magic");
driver.findElement(By.id("submitFrmShared")).click();
//Thread.sleep(10000);
driver.manage().timeouts().implicitlyWait(70, TimeUnit.SECONDS);
driver.manage().timeouts().pageLoadTimeout(70, TimeUnit.SECONDS);
Select dropCountry = new Select(driver.findElement(By.id("txtNewLocation")));
dropCountry.selectByVisibleText("India");
driver.findElement(By.xpath("//button[#class='btn']/label")).click();
driver.manage().timeouts().implicitlyWait(70, TimeUnit.SECONDS);
driver.manage().timeouts().pageLoadTimeout(70, TimeUnit.SECONDS);
//driver.findElement(By.xpath("//span[#class='ds-coachmark-close']")).click();
//driver.manage().timeouts().implicitlyWait(50, TimeUnit.SECONDS);
//driver.manage().timeouts().pageLoadTimeout(70, TimeUnit.SECONDS);
Thread.sleep(10000);
String parentWindowHandler = driver.getWindowHandle(); // Store your parent window
driver.findElement(By.xpath("//li[#class='icon-button add']/span")).click();
driver.findElement(By.xpath("//div[#id='ENCActions']/a/label")).click();
driver.findElement(By.xpath("//label[starts-with(text(),'Create Part...')]")).click();
driver.manage().timeouts().implicitlyWait(70, TimeUnit.SECONDS);
driver.manage().timeouts().pageLoadTimeout(70, TimeUnit.SECONDS);
String subWindowHandler = null;
Set<String> handles = driver.getWindowHandles(); // get all window handles
Iterator<String> iterator = handles.iterator();
while (iterator.hasNext()){
subWindowHandler = iterator.next();
System.out.println("k1");
}
System.out.println(driver.switchTo().window(subWindowHandler).getTitle());
WebDriverWait wait = new WebDriverWait(driver, 10);
WebElement element = driver.findElement(By.xpath("//select[#id='Type-Field']//following-sibling::div//div//input"));
element.click();
Thread.sleep(3000);
element.sendKeys(Keys.BACK_SPACE);
Thread.sleep(3000);
element.sendKeys("Subassy");
Thread.sleep(4000);
driver.findElement(By.xpath("//div[#data-value='Subassy']")).click();
driver.findElement(By.xpath("//span[text()='Description']//parent::td//following-sibling::td//textarea")).sendKeys("Testing");
driver.findElement(By.xpath("//option[text()='BioSc-DS-Chemical']//parent::select")).click();
Thread.sleep(2000);
driver.findElement(By.xpath("//option[text()='BioSc-DS-Chemical']")).click();
driver.findElement(By.xpath("//a[text()='Done']")).click();
driver.manage().timeouts().implicitlyWait(70, TimeUnit.SECONDS);
driver.manage().timeouts().pageLoadTimeout(70, TimeUnit.SECONDS);
System.out.println(driver.switchTo().window(parentWindowHandler).getTitle());
driver.switchTo().frame("content");
driver.switchTo().frame("detailsDisplay");
driver.findElement(By.xpath("//a[#title='Part Details']")).click();
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return driver;
}
This is the stack trace:
Exception in thread "main" org.openqa.selenium.NoSuchElementException: no
such element: Unable to locate element:
{"method":"xpath","selector":"//a[#title='Part Details']"}
(Session info: chrome=66.0.3359.181)
(Driver info: chromedriver=2.38.552522
(437e6fbedfa8762dec75e2c5b3ddb86763dc9dcb),platform=Windows NT 6.1.7601 SP1
x86_64) (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 70.04 seconds
For documentation on this error, please visit:
http://seleniumhq.org/exceptions/no_such_element.html
Build info: version: 'unknown', revision: '5234b32', time: '2017-03-10
09:00:17 -0800'
System info: host: 'TMIC-PCS2200', ip: '3.235.34.200', os.name: 'Windows 7',
os.arch: 'amd64', os.version: '6.1', java.version: '1.8.0_144'
Driver info: org.openqa.selenium.chrome.ChromeDriver
Capabilities [{applicationCacheEnabled=false, rotatable=false,
mobileEmulationEnabled=false, networkConnectionEnabled=false, chrome=
{chromedriverVersion=2.38.552522 (437e6fbedfa8762dec75e2c5b3ddb86763dc9dcb),
userDataDir=C:\Users\KT0047~1\AppData\Local\Temp\scoped_dir14184_21633},
takesHeapSnapshot=true, pageLoadStrategy=normal, databaseEnabled=false,
handlesAlerts=true, hasTouchScreen=false, version=66.0.3359.181,
platform=XP, browserConnectionEnabled=false, nativeEvents=true,
acceptSslCerts=false, acceptInsecureCerts=false,
locationContextEnabled=true, webStorageEnabled=true, browserName=chrome,
takesScreenshot=true, javascriptEnabled=true, cssSelectorsEnabled=true,
setWindowRect=true, unexpectedAlertBehaviour=}]
Session ID: 818a330c1e7b24086d7d06935e830e51
*** Element info: {Using=xpath, value=//a[#title='Part Details']}
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)
I have attached screenshot of the html code.Html code screenshot
In this code I am trying to click on the 'Part Details' link which is inside 'detailsDisplay' frame and this frame is inside another frame 'content'. I am unable to locate the 'Part Details' link element inside 'detailsDisplay' frame.
You can wait for the frame to fully loaded as given below. It may solve your problem.
WebDriverWait wait = new WebDriverWait(driver,60);
wait.until(ExpectedConditions.frameToBeAvailableAndSwitchToIt("content");
wait.until(ExpectedConditions.frameToBeAvailableAndSwitchToIt("detailsDisplay");
driver.findElement(By.xpath("//a[#title='Part Details']")).click();
When you ask a question like this, don't insert the screenshot of the html code. Insert the source. It's easier, for whoever want to answer, try to help.
After the switch to the iframe "detailsDisplay", try to locate your element with:
driver.findElement(By.xpath("//div[#id='tvcTabs0']/div[#class='tabContainer']/ul/li/div[#class='tabcontent]/a[#title='Part Details']")).click();
I didn't test it because I've created this using the screenshot. If you had inserted the source, I could have done a test.
As I see there is an iframe element at the top of page that bounds the element you want to interact with. Maybe you can try to locate "Part Details" link like this:
driver.switchTo().frame(driver.findElement(By.xpath("//a[#title='Part Details']")));
EDIT:
It seems that you are still at outside frame, that's why selenium always throw NoElementException. I have an an idea, maybe you can try to find out if iframe actually contains that element.
// we find all iframes
int size = webDriver.findElements(By.tagName("iframe")).size();
// we loop through all iframes to search for Part Details link
for(int i=0; i<size; i++) {
webDriver.switchTo().frame(i);
int total = webDriver.findElements(By.cssSelector("a[title*='Part Details']")).size();
System.out.println(total);
webDriver.switchTo().defaultContent();
}
We use webDriver.findElements to avoid NoElementException, if webDriver can find element, then total would be 1, otherwise 0. If this works, then you can proceed further. I hope it helps :)
Related
this is just a simple code to obtain all links from a particular section of a web page; click on those links get the title and return back to the parent page and repeat process for next one. But after clicking on 2 links I am getting error "stale element reference: element is not attached to the page document" Please refer code and let me know what I am missing.
I am able to open links in a new tab and get the title of child pages. But I want to open a link in the same tab.
package test;
import java.util.List;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
public class LinkTest {
public static void main (String[] args) throws InterruptedException{
System.setProperty("webdriver.chrome.driver", "C:\\ChromeDriver\\1\\chromedriver.exe");
WebDriver driver = new ChromeDriver();
driver.get("http://www.qaclickacademy.com/practice.php");
WebElement driverFooter = driver.findElement(By.xpath("//div[#id='gf-BIG']"));
WebElement footerC1 = driverFooter.findElement(By.xpath("//table/tbody/tr/td/ul[1]"));
List<WebElement> links = footerC1.findElements(By.tagName("a"));
for(int i=0;i<links.size();i++){
links.get(i).click();
System.out.println(driver.getTitle());
driver.navigate().back();
}
}
}
It should open all links and get the title and return to parent page for next iterator. Below is output and error,
Only local connections are allowed.
Please protect ports used by ChromeDriver and related test frameworks to prevent access by malicious code.
[1550488224.725][WARNING]: Timed out connecting to Chrome, retrying...
Practice Page
REST API Tutorial
Exception in thread "main" org.openqa.selenium.StaleElementReferenceException: stale element reference: element is not attached to the page document
(Session info: chrome=72.0.3626.109)
(Driver info: chromedriver=2.46.628402 (536cd7adbad73a3783fdc2cab92ab2ba7ec361e1),platform=Windows NT 10.0.16299 x86_64) (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 6 milliseconds
For documentation on this error, please visit: http://seleniumhq.org/exceptions/stale_element_reference.html
Build info: version: '2.53.0', revision: '35ae25b', time: '2016-03-15 17:00:58'
System info: host: 'DS-SGH631RNL8', ip: '10.118.59.16', os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '1.8.0_201'
Driver info: org.openqa.selenium.chrome.ChromeDriver
Capabilities [{mobileEmulationEnabled=false, timeouts={implicit=0, pageLoad=300000, script=30000}, hasTouchScreen=false, platform=XP, acceptSslCerts=false, goog:chromeOptions={debuggerAddress=localhost:53075}, acceptInsecureCerts=false, webStorageEnabled=true, browserName=chrome, takesScreenshot=true, javascriptEnabled=true, setWindowRect=true, unexpectedAlertBehaviour=ignore, applicationCacheEnabled=false, rotatable=false, networkConnectionEnabled=false, chrome={chromedriverVersion=2.46.628402 (536cd7adbad73a3783fdc2cab92ab2ba7ec361e1), userDataDir=C:\Users\RUSHIK~1.KAD\AppData\Local\Temp\scoped_dir11700_2428}, takesHeapSnapshot=true, pageLoadStrategy=normal, strictFileInteractability=false, databaseEnabled=false, handlesAlerts=true, version=72.0.3626.109, browserConnectionEnabled=false, proxy={}, nativeEvents=true, locationContextEnabled=true, cssSelectorsEnabled=true}]
Session ID: e1a6bdd0b525d1c6e1d940a2ec156e51
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.RemoteWebElement.execute(RemoteWebElement.java:327)
at org.openqa.selenium.remote.RemoteWebElement.click(RemoteWebElement.java:85)
at test.LinkTest.main(LinkTest.java:23)
You are getting StaleElementReferenceException which comes when the element you are trying to access is no longer available in the dom or has become stale, to correct it you need to pick the elements again and then operate on it. You can modify your code like:
System.setProperty("webdriver.chrome.driver", "C:\\ChromeDriver\\1\\chromedriver.exe");
WebDriver driver = new ChromeDriver();
driver.get("http://www.qaclickacademy.com/practice.php");
WebElement driverFooter = driver.findElement(By.xpath("//div[#id='gf-BIG']"));
WebElement footerC1 = driverFooter.findElement(By.xpath("//table/tbody/tr/td/ul[1]"));
List<WebElement> links = footerC1.findElements(By.tagName("a"));
for(int i=0;i<links.size();i++){
driverFooter = driver.findElement(By.xpath("//div[#id='gf-BIG']"));
footerC1 = driverFooter.findElement(By.xpath("//table/tbody/tr/td/ul[1]"));
List<WebElement> newLinks = footerC1.findElements(By.tagName("a"));
newLinks.get(i).click();
System.out.println(driver.getTitle());
driver.navigate().back();
driver.navigate().refresh();
}
I am practicing on flipkart.com. i am unable to click the product after the search result. The xpath is correct. I tried using scroll function,visible, find by partial linktext, wait, sleep still i am unable to do. Please find the below code.
package Flipkart;
import org.openqa.selenium.By; import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
public class TC2
{
public static void main(String[] args) throws InterruptedException
{
System.setProperty("webdriver.chrome.driver","C:\\Chrome\\chromedriver.exe");
WebDriver driver = new ChromeDriver();
driver.get("https://www.flipkart.com/");
driver.findElement(By.name("q")).sendKeys("Bag");
driver.findElement(By.xpath("html/body/div[1]/div/header/div[1]/div[2]/div/div/div[2]/form/div/div[2]/button")).click();
driver.findElement(By.xpath(".//*[#id='container']/div/div[2]/div[2]/div/div[2]/div/div[3]/div[1]/div[1]/div[1]/div/a[2]")).click();
}
}
Error:
Starting ChromeDriver 2.25.426923 (0390b88869384d6eb0d5d09729679f934aab9eed) on port 17575
Only local connections are allowed.
Exception in thread "main" org.openqa.selenium.NoSuchElementException: no such element: Unable to locate element: {"method":"xpath","selector":".//*[#id='container']/div/div[2]/div[2]/div/div[2]/div/div[3]/div[1]/div[1]/div[1]/div/a[2]"}
(Session info: chrome=58.0.3029.81)
(Driver info: chromedriver=2.25.426923 (0390b88869384d6eb0d5d09729679f934aab9eed),platform=Windows NT 10.0.14393 x86_64) (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 76 milliseconds
For documentation on this error, please visit: http://seleniumhq.org/exceptions/no_such_element.html
Build info: version: 'unknown', revision: 'unknown', time: 'unknown'
System info: host: 'D90T0CQ1', ip: '192.168.162.83', os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '1.8.0_102'
Driver info: org.openqa.selenium.chrome.ChromeDriver
Capabilities [{applicationCacheEnabled=false, rotatable=false, mobileEmulationEnabled=false, networkConnectionEnabled=false, chrome={chromedriverVersion=2.25.426923 (0390b88869384d6eb0d5d09729679f934aab9eed), userDataDir=C:\Users\SALUNK~1\AppData\Local\Temp\scoped_dir12552_16506}, takesHeapSnapshot=true, pageLoadStrategy=normal, databaseEnabled=false, handlesAlerts=true, hasTouchScreen=false, version=58.0.3029.81, platform=XP, browserConnectionEnabled=false, nativeEvents=true, acceptSslCerts=true, locationContextEnabled=true, webStorageEnabled=true, browserName=chrome, takesScreenshot=true, javascriptEnabled=true, cssSelectorsEnabled=true}]
Session ID: a8c3432c9b1e8cce3365db9407fc310f
*** Element info: {Using=xpath, value=.//*[#id='container']/div/div[2]/div[2]/div/div[2]/div/div[3]/div[1]/div[1]/div[1]/div/a[2]}
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:423)
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 Flipkart.TC2.main(TC2.java:15)
Here is the Answer to your Question:
I don't see any such errors/issues in your code. A few words about the solution:
Chrome browser sometimes doesn't opens maximized so you need to maximize the Chrome browser using ChromeOptions class.
If the browser is not maximized certain elements doesn't appers within the Viewport and and may throw NoSuchElementException
Add the argument to disable the infobars through ChromeOptions class.
Your xpath looks vulnerable to me, try to construct logical xpath for the elements on the HTML DOM.
Your own code works at my end with some simple tweaks which opens the Chrome
Browser, navigates to the URL https://www.flipkart.com/, searches for Bag, clicks on Skybags Pixel Plus 03 30 L Backpack and Skybags Pixel Plus 03 30 L Backpack (Grey) is opened in a new tab.
Here is the modified code block:
System.setProperty("webdriver.chrome.driver","C:\\your_directory\\chromedriver.exe");
ChromeOptions options = new ChromeOptions();
options.addArguments("start-maximized");
options.addArguments("disable-infobars");
WebDriver driver = new ChromeDriver(options);
driver.get("https://www.flipkart.com/");
driver.findElement(By.name("q")).sendKeys("Bag");
driver.findElement(By.xpath("html/body/div[1]/div/header/div[1]/div[2]/div/div/div[2]/form/div/div[2]/button")).click();
driver.findElement(By.xpath(".//*[#id='container']/div/div[2]/div[2]/div/div[2]/div/div[3]/div[1]/div[1]/div[1]/div/a[2]")).click();
Let me know if this Answers your Question.
I have tried the same lines of code which you have mentioned and things work for me. Maybe you should try again.
Please try to use small xpath:
Suggestion:
Replace Xpath: html/body/div[1]/div/header/div[1]/div[2]/div/div/div[2]/form/div/div[2]/button with the different Xpath:
//form[#action="/search"]/div/div[2]/button
You should use relative path instead of absolute path because if there are any changes made in the path of the element then that XPath gets failed.
I got the same exception and added implicitly wait. It is working fine now. The code
System.setProperty("webdriver.chrome.driver",System.getProperty("user.dir") + "\\lib\\chromedriver.exe");
WebDriver driver = new ChromeDriver();
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
driver.get("https://www.flipkart.com/");
driver.findElement(By.name("q")).sendKeys("Bag");
driver.findElement(By.xpath("html/body/div[1]/div/header/div[1]/div[2]/div/div/div[2]/form/div/div[2]/button")).click();
driver.findElement(By.xpath("//*[#class='_2cLu-l']")).click();`
Final solution and I can't suggest more than this,
//openChromeBrowser();
driver.get("https://www.flipkart.com/");
driver.findElement(By.name("q")).sendKeys("Bag");
driver.findElement(By.xpath("//form[#action='/search']/div/div[2]/button")).click();
Thread.sleep(5000);
driver.findElement(By.linkText("Puma PUMA Zipper Backpack 26 L Laptop Backpack")).click();
1> Give some wait time and it works
2> Use LinkText for locators for any of the item shown.
And follow what #Monika Singhal has said for quick and efficient results in Automation.
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.
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);
I am new to selenium web driver, I am writing script to login in to the gmail below is the test script that I created.
public class gmailEmail {
public void login() {
ChromeDriver driver=new ChromeDriver();
driver.get("https://www.gmail.com");
driver.findElementById("Email").sendKeys("XXXXX#gmail.com");
driver.findElementByName("signIn").click();
driver.findElementById("Passwd").sendKeys("XXXX");
//driver.findElementByXPath("//*[#id='Passwd']").sendKeys("XXXXX");
driver.findElementByXPath("//*[#id='signIn']").click();
}
When I run this the error is triggering at "driver.findElementById("Passwd")" following error message is displaying
Exception in thread "main" org.openqa.selenium.NoSuchElementException: no such element: Unable to locate element: {"method":"id","selector":"Passwd"}
(Session info: chrome=49.0.2623.112)
(Driver info: chromedriver=2.21.371459 (36d3d07f660ff2bc1bf28a75d1cdabed0983e7c4),platform=Mac OS X 10.10.5 x86_64) (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 40 milliseconds
For documentation on this error, please visit: http://seleniumhq.org/exceptions/no_such_element.html
Build info: version: '2.52.0', revision: '4c2593c', time: '2016-02-11 19:03:33'
System info: host: 'Rameshs-MacBook-Pro.local', ip: '192.168.0.105', os.name: 'Mac OS X', os.arch: 'x86_64', os.version: '10.10.5', java.version: '1.8.0_65'
Driver info: org.openqa.selenium.chrome.ChromeDriver
Capabilities [{applicationCacheEnabled=false, rotatable=false, mobileEmulationEnabled=false, chrome={chromedriverVersion=2.21.371459 (36d3d07f660ff2bc1bf28a75d1cdabed0983e7c4), userDataDir=/var/folders/vx/07vnt7mn2jx4fpm983_tq6gm0000gn/T/.org.chromium.Chromium.S1jNgs}, takesHeapSnapshot=true, databaseEnabled=false, handlesAlerts=true, hasTouchScreen=false, version=49.0.2623.112, platform=MAC, browserConnectionEnabled=false, nativeEvents=true, acceptSslCerts=true, locationContextEnabled=true, webStorageEnabled=true, browserName=chrome, takesScreenshot=true, javascriptEnabled=true, cssSelectorsEnabled=true}]
Session ID: f5790b0589eb054c4e11283c80b82f0e
*** Element info: {Using=id, value=Passwd}
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.RemoteWebDriver.findElement(RemoteWebDriver.java:363)
at org.openqa.selenium.remote.RemoteWebDriver.findElementById(RemoteWebDriver.java:413)
at MobilousLogin.gmailEmail.login(gmailEmail.java:15)
at MobilousLogin.Registration.main(Registration.java:10)
If I debug by inserting a breakpoint at "driver.findElementById("Passwd")" then the whole script is working fine.
Can some one please help me out in understanding what I am doing wrong here?
The error says it isn't able to identify the element that means by the time selenium has executed the command to enter password, the element wasn't loaded or not visible in the UI.
You may want to use ImplicitWait or ExplicitWaits. You can read about them here
You can try ExplicitWait to wait for the Passwd element:
public void login() {
ChromeDriver driver=new ChromeDriver();
driver.get("https://www.gmail.com");
driver.findElementById("Email").sendKeys("XXXXX#gmail.com");
driver.findElementByName("signIn").click();
WebDriverWait wait = new WebDriverWait(driver, 30);
wait.until(ExpectedConditions.presenceOfElementLocated(By.id("Passwd")).sendKeys(""What ever");
driver.findElementByXPath("//*[#id='signIn']").click();
}
try with below code:
public void login() {
ChromeDriver driver=new ChromeDriver();
driver.get("https://www.gmail.com");
driver.findElementById("Email").sendKeys("XXXXX#gmail.com");
driver.findElementByXPath("//*[#id='signIn']").click();
driver.findElementById("Passwd").sendKeys("XXXX");
driver.findElementByXPath("//*[#id='signIn']").click();
}
Add chrome driver capabilities
Try it once.
WebDriver driver = new ChromeDriver();
driver.get("https://www.gmail.com");
driver.manage().timeouts().impliciltyWait(30,TimeUnit.SECONDS);
driver.findElement(By.id("email-display").sendKeys("XXXXX#gmail.com");
driver.findElement(By.id("next"").click();
driver.findElement(By.id("Passwd")).sendKeys("xxxxxx");
driver.findElementByXPath("//*[#id='signIn']").click();