Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
371 views
in Technique[技术] by (71.8m points)

javascript - The method parseDouble(String) is undefined for the type Arc2D

I got this error when I am converting the String to double, I want that value in Double data type

This is my code

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); //

The wave element is

<input type="hidden" value="1000.00" name="avgDiscountRate1">
question from:https://stackoverflow.com/questions/66063066/the-method-parsedoublestring-is-undefined-for-the-type-arc2d

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

You were close enough. You need to initialize the variable room_rate first.

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);

In a single line:

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

However the WebElement seems to have the attribute type="hidden". So you need to removeAttribute() the type attribute and you can use the following solution:

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());

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...