Java 无法使用sendKeys";WebElement类型中的sendKeys(CharSequence[])不适用于参数(字符串)";
我试图在sendKeys方法[type WebElement]中将“String”作为参数发送,但系统将其作为字符序列使用,因此无法获得正确的输出Java 无法使用sendKeys";WebElement类型中的sendKeys(CharSequence[])不适用于参数(字符串)";,java,string,xpath,selenium-webdriver,Java,String,Xpath,Selenium Webdriver,我试图在sendKeys方法[type WebElement]中将“String”作为参数发送,但系统将其作为字符序列使用,因此无法获得正确的输出 public static void setGridDropDownValue(Selenium selenium, WebDriver webDriver, String strGridId, int nRowIndex, int nCellIndex, String strValue) { String strXPath =
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;
}
}
}
public static void setGridDropDownValue(Selenium Selenium、WebDriver WebDriver、字符串strGridId、int nRowIndex、int nCellIndex、字符串strValue)
{
字符串strXPath=“//div[@id=”“+strGridId+”]//table/tbody/tr[2]/td/div/div/div/table/tbody/tr[”+(nRowIndex+2)+“]/td[”+(nCellIndex+1)+“]/”;
selenium.click(strXPath);
双击(strXPath);
strXPath=“//选择”;
selectselstatus=newselect(webDriver.findElement(By.xpath(strXPath));
List we=selStatus.getOptions();
对于(int i=0;i
例如:我的下拉列表有4个选项(部分、完成、验证、删除)。如果选择的值为“部分”,我发送的键为“完成”,则工作正常,但如果选择的值为“已验证”,我发送的键为“完成”,则系统选择“删除”。我不知道它的工作程序,但我认为系统正在比较字符。如果所选值为“已验证”且我发送“部分”,则系统选择“部分”(正常工作)
F.Y.I.:在用户双击该元素之前,我的下拉列表是不可见的
请让我知道是否有任何方法发送“字符串”与sendKeys方法。TIA您可以使用
再次设置JRE系统库。如果使用eclipse,请执行以下步骤:
如果您正在使用eclipse,请遵循以下步骤:
如果您使用的是eclipse,请执行以下步骤:- 1.右键单击项目->生成路径->配置生成路径 2.选择Java编译器->将级别更改为1.7 3.单击应用->确定`
我认为这应该行得通。没有编译错误。我的选项不可见,因此findElement(strxpath)在这里不起作用。您使用的是什么IDE?日食?你的答案和里彭·阿尔·瓦西姆的有什么不同?
Select select = (Select) driver.findElement(By.xpath(strXPath));
select.selectByVisibleText(strValue);