gpt4 book ai didi

java - 我在 expedia.com 网站上使用 pagefactory 找不到使用 id 或 xpath 的按钮

转载 作者:行者123 更新时间:2023-12-02 09:35:09 25 4
gpt4 key购买 nike

我在 expedia.com 网站上使用 pagefactory 找不到使用 id 或 xpath 的按钮。它说没有这样的元素:无法找到元素“tab-flight-tab-flp”。我尝试使用 id 和 xpath。它给出了同样的错误。我想知道这正在发生?它说没有这样的元素:无法找到元素“tab-flight-tab-flp”。我尝试使用 id 和 xpath。它给出了同样的错误。我想知道这正在发生?它说没有这样的元素:无法找到元素“tab-flight-tab-flp”。我尝试使用 id 和 xpath。它给出了同样的错误。我想知道这是怎么回事?

package UsefulPackages;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.FindBy;
import org.openqa.selenium.support.PageFactory;

public class SearchPageFactory {

WebDriver adriver;

@FindBy(id="tab-flight-tab-flp")
WebElement flightTab;

//constructor
public SearchPageFactory(WebDriver driver) {

this.adriver = driver;
PageFactory.initElements(driver, this);
}

public void clickFlightTab(){

flightTab.click();

}

}

import java.util.Set;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.Alert;
import org.openqa.selenium.By;
import org.openqa.selenium.Keys;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import UsefulPackages.SearchPageFactory;

public class FrameworkTestCase {

WebDriver achromeDriver;
String abaseUrl;

SearchPageFactory apagefactory;

@Before
public void setUp() throws Exception {

abaseUrl = "http://www.expedia.com";

System.setProperty("webdriver.chrome.driver", "C:\\Selenium\\ChromeDirver\\chromedriver.exe");

achromeDriver = new ChromeDriver();

apagefactory = new SearchPageFactory(achromeDriver);

chromeDriver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
achromeDriver.manage().window().maximize();
System.out.println("setup completed");

}

@Test

public void test() {

achromeDriver.get(abaseUrl);

WebDriverWait awaittime = new WebDriverWait(achromeDriver, 10);

System.out.println("page factory created");

apagefactory.clickFlightTab();
}





}

最佳答案

您想要获取Flights按钮吗?

picture

它将实现:

  1. id查找:

    @FindBy(id="tab-flight-tab-hp")

  2. 通过xpath查找:

    @FindBy(xpath="//button[@id='tab-flight-tab-hp']")

关于java - 我在 expedia.com 网站上使用 pagefactory 找不到使用 id 或 xpath 的按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57581368/

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