Incorrect JSON Status Mapping for Stale Element

555 views
Skip to first unread message

AL

unread,
Mar 6, 2019, 9:03:37 PM3/6/19
to Selenium Users
Hello all,

The script that is throwing the error is supposed to do the following:
  1. Launch google.com via Firefox
  2. Type pluralsight in the search bar and hit submit
  3. Select the "Images" link
Image results of "pluralsight"
Search results of "pluralsight" (script does not move past this step)

The following is my code:
package com.pluralsight;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;

public class WebDriverTutorial {

   
public static void main(String[] args) {
       
// TODO Auto-generated method stub
       
       
System.setProperty("webdriver.gecko.driver", "C:\\Users\\ALiLLiNOiS\\Desktop\\Drivers\\Gecko\\geckodriver.exe");
       
       
WebDriver driver = new FirefoxDriver();
        driver
.get("http://www.google.com");
       
WebElement searchfield = driver.findElement(By.name("q"));
       
        searchfield
.sendKeys("pluralsight");
        searchfield
.submit();
       
       
//driver.navigate().refresh();
       
WebElement imagesLink= driver.findElements(By.linkText("Images")).get(0);
        imagesLink
.submit();
   
   
}

}

Firefox: 65.0.2 (64-bit)
Selenium: 3.12.0 (Java)

Here is the error:
1551924004098    mozrunner::runner    INFO    Running command: "C:\\Program Files (x86)\\Mozilla Firefox\\firefox.exe" "-marionette" "-foreground" "-no-remote" "-profile" "C:\\Users\\ALILLI~1\\AppData\\Local\\Temp\\rust_mozprofile.rnN4Nu3E5qFS"
1551924005119    addons.webextension.screenshots@mozilla.org    WARN    Loading extension 'scree...@mozilla.org': Reading manifest: Invalid host permission: resource://pdf.js/
1551924005120    addons.webextension.screenshots@mozilla.org    WARN    Loading extension 'scree...@mozilla.org': Reading manifest: Invalid host permission: about:reader*
1551924008327    Marionette    INFO    Listening on port 57000
Mar 06, 2019 8:00:08 PM org.openqa.selenium.remote.ProtocolHandshake createSession
INFO
: Detected dialect: W3C

Mar 06, 2019 8:00:11 PM org.openqa.selenium.remote.ErrorCodes toStatus
INFO
: HTTP Status: '404' -> incorrect JSON status mapping for 'stale element reference' (400 expected)
Exception in thread "main" org.openqa.selenium.StaleElementReferenceException: The element reference of <a class="gb_d" href="https://www.google.com/imghp?hl=en&tab=wi"> is stale; either the element is no longer attached to the DOM, it is not in the current frame context, or the document has been refreshed
For documentation on this error, please visit: http://seleniumhq.org/exceptions/stale_element_reference.html
Build info: version: '3.4.0', revision: 'unknown', time: 'unknown'
System info: host: 'DESKTOP-FHGCOLL', ip: '192.168.1.130', os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '10.0.1'
Driver info: org.openqa.selenium.firefox.FirefoxDriver
Capabilities [{moz:profile=C:\Users\ALiLLiNOiS\AppData\Local\Temp\rust_mozprofile.rnN4Nu3E5qFS, rotatable=false, moz:geckodriverVersion=0.24.0, timeouts={implicit=0.0, pageLoad=300000.0, script=30000.0}, pageLoadStrategy=normal, unhandledPromptBehavior=dismiss and notify, strictFileInteractability=false, moz:headless=false, platform=ANY, moz:accessibilityChecks=false, moz:useNonSpecCompliantPointerOrigin=false, acceptInsecureCerts=false, browserVersion=65.0.2, moz:shutdownTimeout=60000.0, platformVersion=10.0, moz:processID=11104.0, browserName=firefox, javascriptEnabled=true, platformName=windows, setWindowRect=true, moz:webdriverClick=true}]
Session ID: aca7457c-eb79-4518-a521-61bec963acd3
    at java
.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at java
.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
    at java
.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
    at java
.base/java.lang.reflect.Constructor.newInstance(Unknown Source)
    at org
.openqa.selenium.remote.http.W3CHttpResponseCodec.createException(W3CHttpResponseCodec.java:150)
    at org
.openqa.selenium.remote.http.W3CHttpResponseCodec.decode(W3CHttpResponseCodec.java:115)
    at org
.openqa.selenium.remote.http.W3CHttpResponseCodec.decode(W3CHttpResponseCodec.java:45)
    at org
.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:164)
    at org
.openqa.selenium.remote.service.DriverCommandExecutor.execute(DriverCommandExecutor.java:82)
    at org
.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:637)
    at org
.openqa.selenium.remote.RemoteWebElement.execute(RemoteWebElement.java:272)
    at org
.openqa.selenium.remote.RemoteWebElement.click(RemoteWebElement.java:82)
    at com
.pluralsight.WebDriverTutorial.main(WebDriverTutorial.java:24)


Please advise

AL

unread,
Mar 8, 2019, 7:51:45 PM3/8/19
to Selenium Users
Can someone help me please?

sachin patil

unread,
Mar 8, 2019, 11:58:27 PM3/8/19
to seleniu...@googlegroups.com
Hi,


Use the below code,

             WebElement searchfield = driver.findElement(By.name("q"));

       

        searchfield.sendKeys("pluralsight");

        searchfield.submit();        

        //driver.navigate().refresh();

        WebElement imagesLink= driver.findElements(By.linkText("Images")).get(0);

        imagesLink.click();


There is a difference in submit() and click() function().

The functionsubmit() is there to make life easier. You can use it on any element inside of form tags to submit that form.

You can also search for the submit button and use.click()

So the only difference hasclick() to be done on the submit button and cansubmit() be done on any form element.

It's up to you.


Let me know if this works for you.

Best Regard
Sachin Patil
+91-9552619077



--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to selenium-user...@googlegroups.com.
To post to this group, send email to seleniu...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/selenium-users/07e1464c-4153-43fe-a211-52a5cc41f17a%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

AL

unread,
Mar 9, 2019, 8:57:57 AM3/9/19
to Selenium Users
This code works fine with chrome driver but not gecko
Reply all
Reply to author
Forward
0 new messages