点击事件在selenium webdriver中不适用于带有angularjs的UL LI标签
package automation.test;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.interactions.Actions;
import org.openqa.selenium.interactions.SendKeysAction;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.Select;
import org.openqa.selenium.support.ui.WebDriverWait;
import com.sun.xml.internal.txw2.Document;
public class Test {
public static void main(String[] args) {
System.setProperty("webdriver.gecko.driver","../geckodriver.exe");
DesiredCapabilities capabilities=DesiredCapabilities.firefox();
capabilities.setCapability("marionette", true);
WebDriver driver = new FirefoxDriver(capabilities);
String baseUrl = "http://abc/abc/Admin";
driver.get(baseUrl);
driver.findElement(By.id("btnLogin")).click();
driver.findElement(By.linkText("LogOut")).click();
driver.close();
}
}
我的HTML
<a class="dropdown-toggle" href="/abc/Admin/Login/LogOut">LogOut </a>
显示错误。
&#34;线程中的异常&#34; main&#34; org.openqa.selenium.NoSuchElementException:无法找到元素: 注销&#34;
如何解决此问题。
答案 0 :(得分:0)
引入WebDriverWait以等待元素加载。
WebDriverWait wait = new WebDriverWait(driver,30);
wait.until(ExpectedConditions.visibilityOfElementLocated(By.linkText("LogOut "))).click();
答案 1 :(得分:0)
文中有空白,请尝试使用partialLinkText
driver.findElement(By.partialLinkText("LogOut")).click();
答案 2 :(得分:0)
使用css选择器
尝试这个driver.findElement(By.cssSelector("a[href='/abc/Admin/Login/LogOut']")).click()