我希望此值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");
最佳答案
使用.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;