简体   繁体   中英

Selenium C#: Not able to read value from textbox with “pre” html tag

I am trying to read the text value from "Subject" field as mentioned below.

string settingsEmailSubject = iBrowserr.GetValue("//div[@class='sc-view sc-pane sc-panel sc-sheet settings-pane']/div/div[@class='sc-view sc-text-field-view subject-line allow-select']");

But, my code is returning null value. I am seeking your advice to solve this issue.

Notes:

Tried with Webelement , driver.GetAttribute , driver.Selected.GetSelected etc.

xpath:

//div[@class='sc-view sc-pane sc-panel sc-sheet settings-pane']/div/div[@class='sc-view sc-text-field-view subject-line allow-select']/pre[@contenteditable='true' is not working as well.

在此处输入图片说明

You can achieve this by selecting the parent element of the pre and then searching in the element for the pre element:

var parent_of_pre = iBrowserr.FindElement(By.XPath("xpath-got-from-chrome"))
var pre_element = parent_of_pre.FindElement(By.XPath("pre"))
string text_pre_element = pre_element.Text

Note that this will work only if the xpath is correct.

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