首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Selenium Webdriver - findElement原子问题

Selenium Webdriver - findElement原子问题
EN

Stack Overflow用户
提问于 2016-02-02 22:49:10
回答 3查看 2.9K关注 0票数 0

SELENIUM WEBDRIVER - IE

我正在尝试使用以下命令单击链接:

代码语言:javascript
复制
driver.findElement(By.linkText("Previous orders")).click();

我得到了这个错误...我可以让它工作一些时候,但大多数时候我得到这个错误,它是间歇性的,你有什么想法吗?

代码语言:javascript
复制
> 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)

主代码:

代码语言:javascript
复制
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"));
    }
}
EN

回答 3

Stack Overflow用户

发布于 2016-02-02 23:36:00

尝试打开IE的保护模式

  1. 单击/轻击菜单栏上的工具,然后单击Internet Options
  2. 在安全选项卡中,选择每个区域并关闭保护模式

否则你能写main的代码吗?

票数 1
EN

Stack Overflow用户

发布于 2016-02-06 00:23:47

我不认为这个错误是由你方的错误代码引起的。我今天尝试升级到IEDriverServer 2.50,但开始收到同样的错误。我返回到使用2.48作为临时解决方案。其他较新的版本可能会在两者之间工作,这就是我之前使用的。

也可以在该项目的Github页面上查看最近的问题:https://github.com/SeleniumHQ/selenium/issues/1590

票数 0
EN

Stack Overflow用户

发布于 2016-07-04 19:17:39

看起来我找到了可重现的案例。检查此问题的https://github.com/SeleniumHQ/selenium/issues/2421

要点在于这条javascript指令:

代码语言:javascript
复制
var Number="рпоп";

注意,如果你写"number“(第一个小写字母)-它会起作用。问题似乎出在错误的javascript代码解析上。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/35156584

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档