简体   繁体   中英

Select the String value of an element using xpath , in Selenium Java

I am completely new to selenium. I am using Selenium and java.The following is my resulting screen value. I want to select the double quoted data(Test) from this screen, and i want to replace it to a different value.

  "value": "Test",** "createDateTime": "2016-08-23T15:37:06+0100", "channel": "POST", 

Note: the whole data is under a div class =ace_gutter , the parent div class is "aceEditor". After a long struggle i found the following xpath for that row which i want to get the value from.

HTML code:

@11

Xpath: It is this

[@id='aceEditor']/div[1]/div[1]/div[11].

myCode:

String value= driver1.findElement(By.xpath("//*[@id='aceEditor']/div[1]/div[1]/div[11]")).getAttribute("innerHTML") ;

It is giving 11, instead of the actual text( "value": "Test", )from the screen. Could any one Please help me with the code. I have searched enough i am not finding any solution.

To replace the value in the HTML page, you will have to use the executeScript method.

String replace_text = "Text to be replaced";
js = ((JavascriptExecutor) driver)
js.executeScript("return document.getElementById('<id of the element>').innerHTML='" + replace_text + "';");

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