notificationNumberElement

notificationNumberElement

我希望此值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_Conte‌​ntPlaceHolderBody_ContentPlaceHolderBody_ContentPlaceHolderBody_txtNumber"));
string notificationNumber = notificationNumberElement.Text;


如果您的id是动态生成的,请尝试使用CssSelector,如下所示:-

IWebElement notificationNumberElement = driver.FindElement(By.CssSelector("span.inputBold"));
string notificationNumber = notificationNumberElement.Text;

10-02 01:28