如何解决未定义 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());
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。