我希望此值201607000044来自此代码的字符串 -
<SPAN id=ctl00_ctl00_ctl00_ctl00_ContentPlaceHolderCenter_ContentPlaceHolderBody_ContentPlaceHolderBody_ContentPlaceHolderBody_txtNumber class=inputBold style="WIDTH: 200px; DISPLAY: inline-block">201607000044</SPAN>
因为这不起作用 -
IWebElement notificationNumberElement = FindElementById("ctl00_ctl00_ctl00_ctl00_ContentPlaceHolderCenter_ContentPlaceHolderBody_ContentPlaceHolderBody_ContentPlaceHolderBody_txtNumber");
string notificationNumber = notificationNumberElement.GetAttribute("value");
答案 0 :(得分:1)
值是文本。您可以使用Text
成员
string notificationNumber = notificationNumberElement.Text;
答案 1 :(得分:0)
使用.Text
,如下所示: -
IWebElement notificationNumberElement = driver.FindElement(By.Id("ctl00_ctl00_ctl00_ctl00_ContentPlaceHolderCenter_ContentPlaceHolderBody_ContentPlaceHolderBody_ContentPlaceHolderBody_txtNumber"));
string notificationNumber = notificationNumberElement.Text;
如果动态生成id
,请尝试使用CssSelector
,如下所示: -
IWebElement notificationNumberElement = driver.FindElement(By.CssSelector("span.inputBold"));
string notificationNumber = notificationNumberElement.Text;