简体   繁体   English

C#Selenium找不到按钮

[英]C# Selenium can't find button

<form name="loginForm" ng-submit="login()" autocomplete="off" class="ng-pristine ng-invalid ng-invalid-required">
<button type="submit" class="icon-login" ng-disabled="!loginForm.$valid" disabled="enabled"></button>
<input type="text" name="username" id="username" placeholder="Username / Email" autocapitalize="off" autocorrect="off" required="" ng-model="credentials.username" class="ng-pristine ng-invalid ng-invalid-required">
<input type="password" name="password" id="password" placeholder="Password" autocapitalize="off" autocorrect="off" required="" ng-model="credentials.password" class="ng-pristine ng-invalid ng-invalid-required">
</form>    

I tried: 我试过了:

  IWebElement button = driver.FindElement(By.ClassName("icon-login"));

But that didn't work and when I took a screenshot it appears that the button is just not visible while it should be... 但这不起作用,当我拍摄屏幕截图时,该按钮似乎不可见,而应该...

I tried using a wait until too but that just times out even with a minute on it 我也尝试过等一等,但是即使一分钟也只是超时

edit: 编辑:

IWebElement element = new WebDriverWait(driver, TimeSpan.FromSeconds(3)).Until(ExpectedConditions.ElementExists(By.XPath("//form[@name='loginForm']/button[@class='icon-login']")));

Tried that but it justs times out, the element does exsist but not clickable 尝试过但只是超时,该元素确实存在但不可点击

As per your comment update along with the url it seems the Username , Password field and the Login button all are within a form. 根据您的注释更新以及url ,似乎UsernamePassword字段和Login按钮都在表单内。 So once you fill up the Username , Password fields you can straightway invoke the Submit() method to login into the website as follows : 因此,一旦您填写了UsernamePassword字段,就可以直接调用Submit()方法来登录网站,如下所示:

new WebDriverWait(driver, TimeSpan.FromSeconds(3)).Until(ExpectedConditions.ElementToBeClickable(By.XPath("//input[@id='username' and @name='username']"))).SendKeys("refactorcoding");
driver.FindElement(By.XPath("//input[@id='password' and @name='password']")).SendKeys("refactorcoding");
driver.FindElement(By.XPath("//input[@id='password' and @name='password']")).Submit();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM