未定义 Arc2D 类型的 parseDouble(String) 方法

问题描述

当我将 String 转换为 double 时出现此错误,我希望该值采用 Double 数据类型

这是我的代码

WebElement Rm_rate = driver.findElement(By.xpath("//div[@class='MT10']//input[@value= '4424']/following::input[@name = 'avgdiscountRate1']"));
String  r1_rate = Rm_rate.getAttribute("value");
room_rate = Double.parseDouble(r1_rate); //

波浪元素是

<input type="hidden" value="1000.00" name="avgdiscountRate1">

解决方法

你已经足够接近了。您需要先初始化变量 room_rate

WebElement Rm_rate = driver.findElement(By.xpath("//div[@class='MT10']//input[@value= '4424']/following::input[@name = 'avgDiscountRate1']"));
String  r1_rate = Rm_rate.getAttribute("value");
double room_rate = Double.parseDouble(r1_rate);

在一行中:

double room_rate = Double.parseDouble(driver.findElement(By.xpath("//div[@class='MT10']//input[@value= '4424']/following::input[@name = 'avgDiscountRate1']")).getText());

然而,WebElement 似乎具有 type="hidden" 属性。因此,您需要 removeAttribute() type 属性,您可以使用以下解决方案:

WebElement Rm_rate = driver.findElement(By.xpath("//div[@class='MT10']//input[@value= '4424']/following::input[@name = 'avgDiscountRate1']"));
((JavascriptExecutor)driver).executeScript("arguments[0].removeAttribute('type')",Rm_rate);
double room_rate = Double.parseDouble(driver.findElement(By.xpath("//div[@class='MT10']//input[@value= '4424']/following::input[@name = 'avgDiscountRate1']")).getText());