将jar文件更新到selenium 3.0后无法选择下拉选项 [英] unable to select dropdown option after updating jar files to selenium 3.0

查看:96
本文介绍了将jar文件更新到selenium 3.0后无法选择下拉选项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在更新新的 selenium 3.0 beta jar文件后使用以下代码。然而,在早期版本的硒中它完美地运作。

I am using the following code after updating the new selenium 3.0 beta jar files. However in earlier version of selenium it was working perfectly.

我更新了错误信息:


org.openqa.selenium .NoSuchElementException:找不到索引的选项:1

org.openqa.selenium.NoSuchElementException: Cannot locate option with index: 1

有关此错误的文档,请访问: http://seleniumhq.org/exceptions/no_such_element.html
构建信息:版本:'未知',修订版:'2aa21c1',时间:'2016- 08-02 14:59:43 -0700'
系统信息:主机:'GUR-ITD-8C',ip:'172.21.45.117',os.name:'Windows 7',os.arch:' amd64',os.version:'6.1',java.version:'1.8.0_31'
驱动程序信息:driver.version:unknown

For documentation on this error, please visit: http://seleniumhq.org/exceptions/no_such_element.html Build info: version: 'unknown', revision: '2aa21c1', time: '2016-08-02 14:59:43 -0700' System info: host: 'GUR-ITD-8C', ip: '172.21.45.117', os.name: 'Windows 7', os.arch: 'amd64', os.version: '6.1', java.version: '1.8.0_31' Driver info: driver.version: unknown



expedia.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);   
Select LineOfBusiness = new Select(expedia.findElement(By.id("lineOfBusiness")));
LineOfBusiness.selectByIndex(1);
Assert.assertEquals(LineOfBusiness.getFirstSelectedOption().getText(), "HWW Sales");


推荐答案

我不确定你的问题是什么case使用选择类,但是如果你想要一个替代解决方案摆脱这个错误,你可以尝试使用 JavascriptExecutor 如下所示: -

I'm not sure what is the issue in your case using Select class, but if you want an alternate solution to get rid from this error, you can try using JavascriptExecutor as below :-

public static String selectByIndex(WebDriver driver, WebElement select, int index) {

        String javaScript = "var select = arguments[0]; "
                + "select.options[arguments[1]].selected = true;"
                + "return select.selectedOptions[0].text";

        return (String) ((JavascriptExecutor) driver).executeScript(javaScript, select, index);   
}


WebElement select = expedia.findElement(By.id("lineOfBusiness"));

Assert.assertEquals(selectByIndex(expedia, select, 1), "HWW Sales");

这篇关于将jar文件更新到selenium 3.0后无法选择下拉选项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆