我用了CssSelector的定位方法, 麻烦大家帮忙看看这个有什么问题啊,怎么样可以正常定位到这个元素呢,非常感谢!
SelectElement SelectGU = new SelectElement(driver.FindElement(By.CssSelector("select.form-control.ng-pristine.ng-untouched.ng-valid")));
SelectGU.SelectByValue("Shanghai");
一直报错,下面是exception detail:
OpenQA.Selenium.NoSuchElementException was unhandled
HResult=-2146233088
Message=Unable to locate element: {"method":"css selector","selector":"select.form-control.ng-pristine.ng-untouched.ng-valid"}
Source=WebDriver
StackTrace:
at OpenQA.Selenium.Remote.RemoteWebDriver.UnpackAndThrowOnError(Response errorResponse)
at OpenQA.Selenium.Remote.RemoteWebDriver.Execute(String driverCommandToExecute, Dictionary`2 parameters)
at OpenQA.Selenium.Remote.RemoteWebDriver.FindElement(String mechanism, String value)
at OpenQA.Selenium.Remote.RemoteWebDriver.FindElementByCssSelector(String cssSelector)
at OpenQA.Selenium.By.<>c__DisplayClass1e.<CssSelector>b__1c(ISearchContext context)
at OpenQA.Selenium.By.FindElement(ISearchContext context)
at OpenQA.Selenium.Remote.RemoteWebDriver.FindElement(By by)
at DownloadNoGoList.Main(String[] args) in c:\CIO Project\Specflowstudy\1225\selenium\DownloadNoGoList\DownloadNoGoList\Program.cs:line 57
at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()
InnerException: