问题
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:
- 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
回答2:
Set the JRE System Library again. If you use eclipse follow the steps below:
- Go to project properties
- Select Java Build Path at the left panel -> Select Libraries tab 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
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)
回答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