【问题标题】:LinkText is not fetching data from UL UI with angularjsLinkText 没有使用 angularjs 从 UL UI 获取数据
【发布时间】:2016-09-06 05:38:01
【问题描述】:

对于带有 angularjs 的 UL LI 标签的 selenium webdriver,Click 事件不起作用

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>

显示错误喜欢。

“线程“主”中的异常 org.openqa.selenium.NoSuchElementException:无法定位元素: 注销”

如何解决此问题。

【问题讨论】:

    标签: java angularjs selenium selenium-webdriver


    【解决方案1】:

    引入 WebDriverWait 等待元素加载。

    WebDriverWait wait = new WebDriverWait(driver,30);
        wait.until(ExpectedConditions.visibilityOfElementLocated(By.linkText("LogOut "))).click();
    

    【讨论】:

    • 它不起作用显示错误,如“由:org.openqa.selenium.NoSuchElementException:无法找到元素:LogOut”
    • 正如@Guy 建议的那样,尝试使用“partialLinkText”而不是“linkText”定位器并告诉我们结果。
    • WebDriverWait 等待 = new WebDriverWait(driver,30); wait.until(ExpectedConditions.visibilityOfElementLocated(By.partialLinkText("LogOut"))).click();它正在工作,但是当我尝试使用 LogOut 的“粗略事务”Insted 时它不起作用。
    • WebDriverWait 等待 = new WebDriverWait(driver,30); wait.until(ExpectedConditions.visibilityOfElementLocated(By.partialLinkText("Rough Transactions"))).click();它不工作。
    • 尝试使用不同类型的定位器(如 cssSelector 或 xpath)“粗略交易”。
    【解决方案2】:

    文中有空格,试试partialLinkText

    driver.findElement(By.partialLinkText("LogOut")).click();
    

    【讨论】:

      【解决方案3】:

      使用 css 选择器试试这个

      driver.findElement(By.cssSelector("a[href='/abc/Admin/Login/LogOut']")).click()
      

      【讨论】:

        猜你喜欢
        • 2017-10-30
        • 2013-10-14
        • 2017-10-16
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2015-09-25
        • 1970-01-01
        相关资源
        最近更新 更多