输入双精度值时在 selenium 中使用什么代替 sendkeys

What to use instead of sendkey in selenium when inputting a double value

我正在尝试进行计算,然后使用 Selenium Web 驱动程序将结果输入到字段中。但是我收到错误消息“WebElement 类型的方法 sendKeys(CharSequence...) 不适用于 参数(双)

下面是我的代码:

    import java.util.concurrent.TimeUnit;

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

public class ProjectOne {

    public static void main(String[] args) {
        // TODO Auto-generated method stub

        WebDriver driver = new FirefoxDriver();
        driver.get("http://www.techno-geek.co.uk/SeleniumPractice/webform1.html");
        driver.manage().window().maximize();

        driver.findElement(By.xpath(".//*[@id='continue']")).click();


        driver.findElement(By.xpath("//input[@id='COB']")).sendKeys("Toronto");
        driver.findElement(By.xpath(".//*[@id='DOB']")).sendKeys("19th January 1986");  
        driver.findElement(By.xpath("//input[@id='color']")).sendKeys("Cream");
        driver.findElement(By.xpath("//input[@id='food']")).sendKeys("Pizza");


        double a = 14.867;
        double b = 67.902;
        double c = 22567.325;
        double d = 76.908;
        double r1 = a * b;
        double r2 = c/d;


        driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);
        driver.findElement(By.id("multiply")).sendKeys(r1);//1009.49903


        driver.manage().timeouts().implicitlyWait(40, TimeUnit.SECONDS);
        driver.findElement(By.id("divide")).sendKeys(r2);//293.432738


    }


    }

我们必须使用 sendKeys(String.valueOf(doublevalue) 而不是 sendKeys(value)。下面的代码对我有用

driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);
        driver.findElement(By.id("multiply")).sendKeys(String.valueOf(r1));//1009.49903


        driver.manage().timeouts().implicitlyWait(40, TimeUnit.SECONDS);
        driver.findElement(By.id("divide")).sendKeys(String.valueOf(r2));//293.432738

你必须使用对我有用的String.valueOf(doublevalue)转换成字符串格式