2016-09-20 9 views
2

計算を行い、その結果をSelenium Web Driverを使用してフィールドに入力しようとしています。私たちは、使用する必要がdouble値を入力するときにseleniumのsendkeyの代わりに使用するもの

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 


    } 


    } 

答えて

0

:私のコードですが、エラーに以下

「WebElementは 引数(ダブル)には適用されませんタイプのメソッドのSendKeys(のCharSequenceを...)」取得していますSendKeys SendKeysの代わり(String.valueOf(のdoubleValue)(値)。次のコードは、私のため

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 
2

を働いたあなたは私

作品 String.valueOf(doublevalue)を使用して文字列の形式に変換する必要があります
関連する問題