unable to use sendKeys“sendKeys(CharSequence[]) in the type WebElement is not applicable for the arguments (String)”

北城以北 提交于 2021-01-27 21:10:49

问题


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.

    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).

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


回答1:


Follow the steps below if you are using eclipse:

  1. Right click on your java project and select Build Path -> Click on Configure Build Path...
  2. In project properties window: Click/select Java Compiler at the left panel
  3. At the right panel: change the Compiler compliance level from 1.4 to 1.7 or higher
  4. Lastly Click on Apply and OK




回答2:


Set the JRE System Library again. If you use eclipse follow the steps below:

  1. Go to project properties
  2. Select Java Build Path at the left panel -> Select Libraries tab at the right
  3. Click/select JRE System Library[] -> Click Edit button at the right side
  4. Set your preferred JRE and click Finish button
  5. Lastly click OK button from the project properties pop up window

Instead of editing you can also do by deleting and adding. The steps are:

  1. Right-click on project » Properties » Java Build Path
  2. Select Libraries tab
  3. Find the JRE System Library and remove it
  4. Click Add Library... button at right side » Add the JRE System Library (Workspace default JRE)



回答3:


You can use Select class

Select select = (Select) driver.findElement(By.xpath(strXPath));
select.selectByVisibleText(strValue);



回答4:


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`

I think this should work. No compilation error.



来源:https://stackoverflow.com/questions/23102350/unable-to-use-sendkeyssendkeyscharsequence-in-the-type-webelement-is-not-ap

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!