gpt4 book ai didi

java - 我想验证网站的菜单栏选项卡而不是单击它们

转载 作者:行者123 更新时间:2023-11-30 01:56:21 25 4
gpt4 key购买 nike

我想验证站点中的菜单栏选项卡,以确认选项卡名称与其应有的名称完全相同并打印它们。我尝试使用 linkText() 来做到这一点,但我不知道如何验证它们。

public class Automate2 {

public static void main(String[] args) {

System.setProperty("webdriver.gecko.driver","geckodriver.exe");
WebDriver driver = new FirefoxDriver();
driver.get("https://www.toolsqa.com/");
driver.manage().window().maximize();

driver.findElement(By.linkText("Home"));
}
}

最佳答案

请尝试代码中提到的任何断言。但是我的代码在 chrome 上运行而不是 Firefox,但断言方法是相同的。

package SeleniumPractice;

import java.io.File;
import org.junit.Assert;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;

public class TestSOF {

public static void main(String[] args) {
// TODO Auto-generated method stub
File filepath=new File(System.getProperty("user.dir") + "\\Executables\\chromedriver.exe" );
System.setProperty("webdriver.chrome.driver", filepath.getAbsolutePath());
WebDriver driver=new ChromeDriver();
driver.get("https://www.toolsqa.com/");
driver.manage().window().maximize();
WebDriverWait wait = new WebDriverWait(driver, 10);
Assert.assertEquals("HOME",wait.until(ExpectedConditions.presenceOfElementLocated(By.cssSelector(".menu-text"))).getText());
Assert.assertTrue(wait.until(ExpectedConditions.presenceOfElementLocated(By.cssSelector(".menu-text"))).isDisplayed());

System.out.println("Pass");


}

}

请告诉我代码是否有效。

关于java - 我想验证网站的菜单栏选项卡而不是单击它们,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54381263/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com