sanjuro8998
sanjuro8998

Reputation: 1271

Selenium Webdriver - findElement atom issue

SELENIUM WEBDRIVER - IE

I'm trying to click on a link by using the following command:

driver.findElement(By.linkText("Previous orders")).click();

and I'm getting this error ... I could make it work some times but most of the time I get this error, it's intermitent, any ideas?

> Started InternetExplorerDriver server (32-bit)
2.50.0.0
Listening on port 25630
Only local connections are allowed
Exception in thread "main" org.openqa.selenium.WebDriverException: A JavaScript error was encountered executing the findElement atom. (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 46 milliseconds
Build info: version: '2.50.1', revision: 'd7fc91b', time: '2016-01-29 19:04:49'
System info: host: 'ABC598-L1BCDL9', ip: 'xxx.xxx.xxx.xxx', os.name: 'Windows 7', os.arch: 'amd64', os.version: '6.1', java.version: '1.8.0_71'
Driver info: org.openqa.selenium.ie.InternetExplorerDriver
Capabilities [{browserAttachTimeout=0, enablePersistentHover=true, ie.forceCreateProcessApi=false, pageLoadStrategy=normal, ie.usePerProcessProxy=false, ignoreZoomSetting=false, handlesAlerts=true, version=11, platform=WINDOWS, nativeEvents=true, ie.ensureCleanSession=false, elementScrollBehavior=0, ie.browserCommandLineSwitches=, requireWindowFocus=false, browserName=internet explorer, initialBrowserUrl=http://localhost:25630/, takesScreenshot=true, javascriptEnabled=true, ignoreProtectedModeSettings=false, enableElementCacheCleanup=true, cssSelectorsEnabled=true, unexpectedAlertBehaviour=dismiss}]
Session ID: 9865fcae-fa06-46b5-a621-d8390978c515
*** Element info: {Using=link text, value=Previous orders}
    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.findElementByLinkText(RemoteWebDriver.java:428)
    at org.openqa.selenium.By$ByLinkText.findElement(By.java:246)
    at org.openqa.selenium.remote.RemoteWebDriver.findElement(RemoteWebDriver.java:355)
    at Test.main(Test.java:27)

Main Code:

import java.util.concurrent.TimeUnit;
import javax.swing.JOptionPane;
import org.openqa.selenium.Alert;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.ie.InternetExplorerDriver;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.security.UserAndPassword;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.Select;
import org.openqa.selenium.support.ui.WebDriverWait;

public class Test {

    public static void main(String[] args) throws InterruptedException {

        String cartId = JOptionPane.showInputDialog("Type the Cart ID:");

        System.setProperty("webdriver.ie.driver",
                "C:\\Users\\USER_ADMIN\\Downloads\\Selenium Webdriver\\IEDriverServer.exe");
        DesiredCapabilities returnCapabilities = DesiredCapabilities.internetExplorer();
        returnCapabilities.setCapability(InternetExplorerDriver.ENABLE_PERSISTENT_HOVERING, false);
        WebDriver driver = new InternetExplorerDriver(returnCapabilities);
        driver.manage().timeouts().implicitlyWait(120, TimeUnit.SECONDS);
        driver.get("https://k06proxy012.sby.com/procurement/buyondemand/common/enUS/index.html");
        driver.findElement(By.linkText("Log in to Buy on demand (Bond)")).click();

        login(driver);

        // START
        driver.findElement(By.linkText("Previous orders")).click();
        driver.findElement(By.linkText("Search previous orders")).click();
        new Select(driver.findElement(By.id("FIELD1"))).selectByVisibleText("Cart ID");
        driver.findElement(By.id("VALUE1")).clear();
        driver.findElement(By.id("VALUE1")).sendKeys(cartId);
        driver.quit();

    }

    public static void login(WebDriver driver) {
        WebDriverWait wait = new WebDriverWait(driver, 10);
        Alert alert = wait.until(ExpectedConditions.alertIsPresent());
        alert.authenticateUsing(new UserAndPassword("user", "pass"));
    }
}

Upvotes: 0

Views: 3002

Answers (3)

skaeff
skaeff

Reputation: 753

It seems that i found the reproducable case. Check this issue https://github.com/SeleniumHQ/selenium/issues/2421

The point is in this javascript instruction:

var Number="рпоп";

Note, that if you write "number" (first small letter) - it will be working. It seems the problem is in incorrect javascript code parsing.

Upvotes: 0

zserdely
zserdely

Reputation: 113

I don't think the error is caused by erroneous code on your part. I tried upgrading to IEDriverServer 2.50 today and started receiving the same error. I returned to using 2.48 as a temporary workaround. Other newer versions may work between the two, this is just what I used previously.

Also see this recent issue on the project's Github page: https://github.com/SeleniumHQ/selenium/issues/1590

Upvotes: 0

Walid El Ajmi
Walid El Ajmi

Reputation: 33

Try to turn protected mode on IE

  1. Click/tap on tools on the menu bar, and Internet Options
  2. In the Security tab, select every zone and turn off protected mode

else can you write the main's code

Upvotes: 1

Related Questions