Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/360.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/471.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 无法使用sendKeys";WebElement类型中的sendKeys(CharSequence[])不适用于参数(字符串)";_Java_String_Xpath_Selenium Webdriver - Fatal编程技术网

Java 无法使用sendKeys";WebElement类型中的sendKeys(CharSequence[])不适用于参数(字符串)";

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 =

我试图在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;
        }
    }           
}
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,请执行以下步骤:

  • 转到项目属性
  • 选择左侧面板上的Java构建路径->选择右侧的库选项卡
  • 单击/选择JRE系统库[]->单击右侧的编辑按钮
  • 设置您的首选JRE并单击Finish按钮
  • 最后,单击“项目属性”弹出窗口中的“确定”按钮
  • 您也可以通过删除和添加来代替编辑。这些步骤是:

  • 右键单击项目»属性»Java构建路径
  • “选择库”选项卡
  • 找到JRE系统库并将其删除
  • 单击添加库。。。右侧按钮»添加JRE系统库 (工作区默认JRE)

  • 如果您正在使用eclipse,请遵循以下步骤:

  • 右键单击java项目并选择BuildPath->单击ConfigureBuildPath
  • 在“项目属性”窗口中:单击/选择左侧面板上的Java编译器
  • 在右侧面板:将编译器符合性级别从1.4更改为1.7或更高
  • 最后单击应用并确定

  • 如果您使用的是eclipse,请执行以下步骤:- 1.右键单击项目->生成路径->配置生成路径 2.选择Java编译器->将级别更改为1.7 3.单击应用->确定`


    我认为这应该行得通。没有编译错误。

    我的选项不可见,因此findElement(strxpath)在这里不起作用。您使用的是什么IDE?日食?你的答案和里彭·阿尔·瓦西姆的有什么不同?
    Select select = (Select) driver.findElement(By.xpath(strXPath));
    select.selectByVisibleText(strValue);