Событие клика не работает в selenium webdriver для тега UL LI с angularjs

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>

Отображается ошибка Like.

«Исключение в потоке« main »org.openqa.selenium.NoSuchElementException: невозможно найти элемент: LogOut»

Как решить эту проблему.

0
Nitesh Tailor 6 Сен 2016 в 08:38

3 ответа

Лучший ответ

Введите WebDriverWait, чтобы дождаться загрузки элемента.

WebDriverWait wait = new WebDriverWait(driver,30);
    wait.until(ExpectedConditions.visibilityOfElementLocated(By.linkText("LogOut "))).click();
0
Sandipan Pramanik 6 Сен 2016 в 06:03

Попробуйте это, используя селектор css

driver.findElement(By.cssSelector("a[href='/abc/Admin/Login/LogOut']")).click()
0
Devdutta Goyal 6 Сен 2016 в 06:34

В тексте есть пробелы, попробуйте использовать partialLinkText

driver.findElement(By.partialLinkText("LogOut")).click();
0
Guy 6 Сен 2016 в 06:19