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());
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…