Java 无法在类型 WebElement 中使用 sendKeys"sendKeys(CharSequence[]) 不适用于参数 (String)"
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/23102350/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
unable to use sendKeys"sendKeys(CharSequence[]) in the type WebElement is not applicable for the arguments (String)"
提问by Puneet Purohit
I am trying to send "String" as argument in sendKeys method [type WebElement] but system is using it as char sequence, so I am not getting proper output.
我试图在 sendKeys 方法 [type WebElement] 中发送“String”作为参数,但系统将其用作字符序列,所以我没有得到正确的输出。
public static void setGridDropDownValue(Selenium selenium, WebDriver webDriver, String strGridId, int nRowIndex, int nCellIndex, String strValue)
{
String strXPath = "//div[@id='"+strGridId+"']//table/tbody/tr[2]/td/div/div/table/tbody/tr["+(nRowIndex+2)+"]/td["+(nCellIndex+1)+"]/";
selenium.click(strXPath);
selenium.doubleClick(strXPath);
strXPath = "//select";
Select selStatus = new Select(webDriver.findElement(By.xpath(strXPath)));
List<WebElement> we = selStatus.getOptions();
for(int i = 0; i< we.size();i++)
{
WebElement wei = we.get(i);
System.out.println("Options : "+wei.getText().toString());
if(wei.getText().toString().equals(strValue))
{
wei.sendKeys(strValue);
break;
}
}
}
For example : My dropdown have 4 options(Partial,Done,Verified,Delete). If selected value is "Partial" and I am sending key "Done" then it is working fine, but if selected value is "Verified" and I am sending "Done" then system is selecting "Delete". I am not getting its working procedure but I think system is comparing characters. If selected value is "Verified" and I am sending "Partial" then system is selecting "Partial"(working proper).
例如:我的下拉菜单有 4 个选项(部分、完成、已验证、删除)。如果选择的值是“部分”并且我正在发送键“完成”,那么它工作正常,但如果选择的值是“已验证”并且我正在发送“完成”,那么系统正在选择“删除”。我没有得到它的工作程序,但我认为系统正在比较字符。如果选择的值为“已验证”并且我正在发送“部分”,则系统正在选择“部分”(正常工作)。
F.Y.I. : My dropdown is invisible until user double click on that element.
仅供参考:在用户双击该元素之前,我的下拉列表是不可见的。
Please let me know if there is any way to send "String" with sendKeys method. TIA
请让我知道是否有任何方法可以使用 sendKeys 方法发送“字符串”。TIA
回答by xyz
回答by Ripon Al Wasim
Set the JRE System Library again. If you use eclipse follow the steps below:
再次设置 JRE 系统库。如果您使用 eclipse,请按照以下步骤操作:
- Go to project properties
- Select Java Build Pathat the left panel -> Select Librariestab at the right
- Click/select JRE System Library[] -> Click Edit button at the right side
- Set your preferred JRE and click Finish button
- Lastly click OK button from the project properties pop up window
- 转到项目属性
- 在左侧面板中选择Java Build Path->在右侧选择Libraries选项卡
- 单击/选择 JRE System Library[] -> 单击右侧的 Edit 按钮
- 设置您的首选 JRE 并单击“完成”按钮
- 最后从项目属性弹出窗口中单击确定按钮
Instead of editing you can also do by deleting and adding. The steps are:
除了编辑,您还可以通过删除和添加来完成。步骤是:
- Right-click on project ? Properties ? Java Build Path
- Select Libraries tab
- Find the JRE System Library and remove it
- Click Add Library... button at right side ? Add the JRE System Library (Workspace default JRE)
- 右键单击项目 ? 特性 ?Java 构建路径
- 选择库选项卡
- 找到 JRE 系统库并将其删除
- 单击右侧的 Add Library... 按钮?添加 JRE 系统库(工作区默认 JRE)
回答by Ripon Al Wasim
Follow the steps below if you are using eclipse:
如果您使用的是 eclipse,请按照以下步骤操作:
- Right click on your java project and select Build Path -> Click on Configure Build Path...
- In project properties window: Click/select Java Compiler at the left panel
- At the right panel: change the Compiler compliance level from 1.4 to 1.7 or higher
- Lastly Click on Apply and OK
- 右键单击您的 java 项目并选择 Build Path -> 单击 Configure Build Path...
- 在项目属性窗口中:单击/选择左侧面板中的 Java Compiler
- 在右侧面板:将编译器合规性级别从 1.4 更改为 1.7 或更高
- 最后点击应用和确定
回答by Deepak
If you are using eclipse, follow below steps:- 1.Right click your project-> Build Path->Configure Build Path 2.Select Java Compiler-> Change level to 1.7 3.Click Apply-> OK`
如果您使用的是eclipse,请按照以下步骤操作:- 1.右键单击您的项目-> Build Path->Configure Build Path 2.选择Java Compiler-> Change level to 1.7 3.单击Apply-> OK`
I think this should work. No compilation error.
我认为这应该有效。没有编译错误。