繁体   English   中英

如何为 span 标签内的标签查找定位器 xpath/cssselector?

[英]How to find locator xpath/cssselector for a tag inside the span tag?

这是 HTML 代码[在此处输入图像描述][2]

我尝试了下面的一个。 它正在工作。 但是在转换为 TestNG 时,代码会抛出错误。

WebElement userActions = driver.findElement(By.xpath("//div[@class='row col-md-12 col-sm-12']"));
WebElement activateButton = userActions.findElements(By.xpath("//span[@class='ng-scope']")).get(1); 
activateButton.click();

错误:

org.openqa.selenium.NoSuchElementException: no such element: Unable to locate element: {"method":"xpath","selector":"//div[@class='row col-md-12 col-sm-12']"}
  (Session info: chrome=102.0.5005.115)


TestNG:

    @Test(dependsOnMethods= {"selectClient"})
    public void activateUser() throws InterruptedException {
        WebElement userActions = driver.findElement(By.xpath("//div[@class='row col-md-12 col-sm-12']"));
        WebElement activateButton = userActions.findElements(By.xpath("//span[@class='ng-scope']")).get(1);
        activateButton.click();
        DateTimeFormatter DTF = DateTimeFormatter.ofPattern("dd MMMM yyyy");
        LocalDate date=LocalDate.now();
        WebElement mve = driver.findElement(By.xpath("//form/div[3]/div/input[@id='activationDate' and @type='text']"));
        mve.sendKeys(DTF.format(date));
        mve.sendKeys(Keys.TAB);
        WebElement activateClient = driver.findElement(By.xpath("//*[@id=\"save\" and @has-permission=\"ACTIVATE_CLIENT\" and @type='submit']"));
        activateClient.click();
        System.out.println("User Activation Successfully");
    }

  

您是否尝试过 belwo ExplicitWait

import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;

WebDriverWait wait = new WebDriverWait(driver,30);


userActions = wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("Xpath")));

或者

userActions = wait.until(ExpectedConditions.presenceOfElementLocated(By.xapth("Xpath")));

或者

userActions = wait.until(ExpectedConditions.elementToBeClickable(By.xpath("Xpath")));

暂无
暂无

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

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