Error with selenium.WebElement.sendKeys ()

I am building a small application for performing automatic checks on the Magento website using Selenium WebDriver in Java. I am working on learning Java, so I am adamant in understanding this with Java, rather than switching to Ruby or Python.

package com.huuginn.seleniumMagento;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;

/**
 * selenium app for completing checkout in magento
 *
 */
public class App 
{
    public static void main( String[] args )
    {
        //      MagentoCatalog c = new MagentoCatalog();
        WebDriver driver = new FirefoxDriver();

        driver.get("http://plmkt.huuginn.com/");

        WebElement searchField = driver.findElement(By.id("search"));

        System.out.println(searchField.getClass().getName());
        searchField.clear();
        searchField.sendKeys("sample");
        searchField.submit();
    }
}

My getName () line confirms that I get the item I want from the page.

I get this error while compiling:

[INFO] Compilation error /seleniumMagento/src/main/java/com/huuginn/seleniumMagento/App.java:[25,13] sendKeys (java.lang.CharSequence ...) in org.openqa.selenium.WebElement cannot apply to (java.lang.String)

sendKeys expects a type parameter that implements CharSequence (java.lang.String qualifies as such), so I don’t understand why I get this error.

Java 1.6 Selenium 2.19, Maven.

+3
3

sendKeys(). , var-ary, CharSequence... CharSequence.

, Java 6. , maven .

searchField.sendKeys(new String[] { "sample" });

.

+4

. Java , Maven . pom.xml:

  <plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-compiler-plugin</artifactId>
    <version>2.0.2</version>
    <configuration>
      <source>1.5</source>
      <target>1.5</target>
    </configuration>
  </plugin>

"SAMPLE" sendKeys(), .

+1

When you create a project, make sure that you select “Use the JRE runtime: JavaSE-1.6. You can successfully run the test with any Sendkeys error. 100% this will work.

+1
source

Source: https://habr.com/ru/post/1548044/


All Articles