-1

I was able to find the element in webdriver below versions, But with the latest version not able to find the element driver.findElement(By.id("dropdownMenu")).click();

Get this in console:

    1491224447464   geckodriver INFO    Listening on 127.0.0.1:14273
1491224448607   mozprofile::profile INFO    Using profile path C:\Users\COMPIN~1\AppData\Local\Temp\rust_mozprofile.btmAM70uon4k
1491224448614   geckodriver::marionette INFO    Starting browser C:\Program Files (x86)\Mozilla Firefox\firefox.exe with args []
1491224448633   geckodriver::marionette INFO    Connecting to Marionette on localhost:65438
1491224450952   Marionette  INFO    Listening on port 65438
Apr 03, 2017 6:30:53 PM org.openqa.selenium.remote.ProtocolHandshake createSession
INFO: Detected dialect: W3C
JavaScript warning: https://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js, line 1: Using //@ to indicate sourceMappingURL pragmas is deprecated. Use //# instead
JavaScript error: https://qa.xyz.com/assets/js/custom.js?1491224506, line 12601: TypeError: $(...).select2 is not a function
Exception in thread "main" org.openqa.selenium.NoSuchElementException: Unable to locate element: #dropdownMenu
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: 'CO-PC', ip: '169.254.250.92', os.name: 'Windows 7', os.arch: 'amd64', os.version: '6.1', java.version: '1.8.0_111'
Driver info: org.openqa.selenium.firefox.FirefoxDriver
Capabilities [{moz:profile=C:\Users\CO~1\AppData\Local\Temp\rust_mozprofile.btmAM70uon4k, rotatable=false, timeouts={implicit=0, pageLoad=300000, script=30000}, pageLoadStrategy=normal, platform=ANY, specificationLevel=0, moz:accessibilityChecks=false, acceptInsecureCerts=false, browserVersion=53.0, platformVersion=6.1, moz:processID=6952, browserName=firefox, platformName=windows_nt}]
Session ID: 76cd7017-8b8b-463f-84a4-c580b6a58bf8
*** Element info: {Using=id, value=dropdownMenu}
    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.http.W3CHttpResponseCodec.createException(W3CHttpResponseCodec.java:133)
    at org.openqa.selenium.remote.http.W3CHttpResponseCodec.decode(W3CHttpResponseCodec.java:99)
    at org.openqa.selenium.remote.http.W3CHttpResponseCodec.decode(W3CHttpResponseCodec.java:43)
    at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:163)
    at org.openqa.selenium.remote.service.DriverCommandExecutor.execute(DriverCommandExecutor.java:82)
    at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:604)
    at org.openqa.selenium.remote.RemoteWebDriver.findElement(RemoteWebDriver.java:371)
    at org.openqa.selenium.remote.RemoteWebDriver.findElementById(RemoteWebDriver.java:420)
    at org.openqa.selenium.By$ById.findElement(By.java:218)
    at org.openqa.selenium.remote.RemoteWebDriver.findElement(RemoteWebDriver.java:363)
    at WebApp.mc.main(mc.java:29)
Rick
  • 91
  • 11
  • I'm seeing a JS execution error too. Is that causing issue? Is the element displayed as expected? – Tatsuyuki Ishi Apr 03 '17 at 13:20
  • WIth same code line, I tried in my friend lap which has lower version of webdriver, It is working fine. I have pasted all the console output here @TatsuyukiIshi – Rick Apr 03 '17 at 13:34
  • @Rick If you are using latest version of geckodriver, make sure your firefox browser is also the latest one, do not use old firefox version along with latest geckodriver – Shoaib Akhtar Apr 03 '17 at 13:38
  • @ShoaibAkhtar My browser is uptodate 53.0b8 (32-bit) – Rick Apr 03 '17 at 13:41
  • Give it a try once with other locator like css or xpath once and see if it works in this case for you and in your friend's laptop. You can follow this link to generate xpath-http://learn-automation.com/how-to-write-dynamic-xpath-in-selenium/ – Shoaib Akhtar Apr 03 '17 at 14:07
  • @ShoaibAkhtar Used Fire Path to generate Xpath, But it is of no use. – Rick Apr 04 '17 at 03:50

1 Answers1

0

Please ensure the following:

  1. You are using the latest version of Selenium. v 3.x.x & latest version of the gecko driver along with the latest version of Mozilla Firefox Browser.

  2. To work with Selenium 3.x.x you need to download appropriate gecko driver.

  3. While writing your code, you need to mention the following in the very beginning:

System.setProperty("webdriver.gecko.driver","C:\\your_location\\geckodriver.exe");

  1. Then proceed with initializing your driver.

  2. Once you access the url introduce ImplicitlyWait for the ajax extensions & js extensions to load.

  3. As the error is "NoSuchElementException", check if the element can be identified with that ID as an unique element.

  4. Else try to use other attributes like name/css/xpath.

Let me know if this helps you.

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
  • 1. The gecko driver and Mozilla firefox is updated one. 2. Do have appropriate driver. 3. I have set it right, If not we will be shown with the error. – Rick Apr 04 '17 at 03:51
  • @Rick can you share the relevant HTML DOM & your code? – undetected Selenium Apr 04 '17 at 03:58
  • Where can I get the Html DOM – Rick Apr 05 '17 at 04:35
  • public class mc { public static void main(String[] args) throws InterruptedException { WebDriver driver; System.setProperty("webdriver.gecko.driver", "D:\\geckodriver.exe"); driver =new FirefoxDriver(); driver.get("https://xyz/"); driver.findElement(By.xpath("html/body/nav/div/div[2]/div[2]/ul/li/a")).click(); Thread.sleep(5000); driver.findElement(By.id("email")).sendKeys("qwerty"); driver.findElement(By.xpath(".//*[@id='pwd']")).sendKeys("qwerty"); driver.findElement(By.xpath(".//*[@id='prd_login']")).click(); } } – Rick Apr 05 '17 at 04:40
  • As your error is: `NoSuchElementException: Unable to locate element: #dropdownMenu` so can you update that part of the code? – undetected Selenium Apr 05 '17 at 04:57
  • I used this before, After that changed to Xpath. Still didnt work //driver.findElement(By.id("dropdownMenu")).click(); //driver.findElement(By.linkText("Your Profile")).click(); – Rick Apr 05 '17 at 04:59
  • @Rick incase it's a public url, can you share the url? – undetected Selenium Apr 05 '17 at 04:59
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/139923/discussion-between-rick-and-dev). – Rick Apr 05 '17 at 05:08
  • Url is not public – Rick Apr 05 '17 at 05:09