The method sendKeys(CharSequence[]) in the type WebElement is not applicable for the arguments (String)

自闭症网瘾萝莉.ら 提交于 2019-11-27 15:08:10
Venkatesh Pothula

It has a simple solution. Change your compiler compliance level from 1.4 to 1.7.

Follow these steps in your 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
    (Select which is higher version in your eclipse)
  4. Lastly Click on Apply and OK

Now check your code. it will never show the same error.

summer
element.sendKeys(new String[]{"Hello, selenium"});

My code looks like this, it's working.

There are two possible solution for this

1- Change the compiler version from old version to 1.5 or greater.

2- Change the JRE version from JRE8 to JRE7.

I have created a detailed article on this may be it will help.

http://learn-automation.com/solution-for-sendkeyscharsequence-in-selenium/

Try to click into the WebElement before you sending keys to it:

public static void login(WebDriver driver, String userName, String password) {
    driver.get("loginPage.html");
    Thread.sleep(3000);
    driver.findElement(By.id("username")).click();
    driver.findElement(By.id("username")).clear();
    driver.findElement(By.id("username")).sendKeys(userName);
    Thread.sleep(TestConfiguration.time);
    driver.findElement(By.id("password")).click();
    driver.findElement(By.id("password")).clear();
    driver.findElement(By.id("password")).sendKeys(password);
    Thread.sleep(3000);
    driver.findElement(By.name("login")).click();
    Thread.sleep(3000);
}

You should use clear() method to clear the input field before using sendKeys().

You can try by replacing your following lines of code:

        driver.findElement(By.id("password")).sendKeys("nag123");
        driver.findElement(By.id("repassword")).sendKeys);
        driver.findElement(By.id("altemail")).sendKeys();
        driver.findElement(By.id("mobileno")).sendKeys("7894561230");
        driver.findElement(By.id("imageField")).click();

to

        driver.findElement(By.id("password")).sendKeys("nag123");
        driver.findElement(By.id("repassword")).sendKeys("");
        driver.findElement(By.id("altemail")).sendKeys("");
        driver.findElement(By.id("mobileno")).sendKeys("7894561230");
        driver.findElement(By.id("imageField")).click();

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)

Depending on the version of java you need to either convert the primitive (i.e. Char) to String (look here: http://tech.deepumohan.com/2013/03/java-how-to-convert-primitive-char-to.html)

Or switch to a java version that would do it for you (see here: http://java-performance.info/changes-to-string-java-1-7-0_06/)

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