简体   繁体   中英

how to get updated hidden field value using Selenium webdriver in java

I am trying to get the hidden field value using below code but getting the default value as 0.69163 .

WebElement hiddenInput = ieDriver.findElement(By.id("form_base_amount_input_hidden"));
String currencyConverted = hiddenInput.getAttribute("value");

old value:

<input name="base_amount" id="form_base_amount_input_hidden" value="0.69163" type="hidden">

new value:

<input name="base_amount" id="form_base_amount_input_hidden" value="383.852" type="hidden">

I think only via JavaScriptExecutor:

JavascriptExecutor je = (JavascriptExecutor) ieDriver;
String script = "document.getElementsById('form_base_amount_input_hidden')[0].setAttribute('value', '383.852');");
je.executeScript(script);
String  text = (String)((JavascriptExecutor) driver).executeScript("return document.getElementsByName('base_amount')[0].value;");  

请执行此语句,希望您能得到结果。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM