我怎样才能让 selenium 等到下一页加载相同的 URL 并具有相同的字段

How can i make selenium wait till the next page is loaded with same URL and have same fields

我的代码如下所示:

driver.findElement(By.id("submit")).sendKeys(Keys.ENTER); 
driver.manage().timeouts().implicitlyWait(60, TimeUnit.SECONDS);
driver.findElement(By.id("search-trigger")).sendKeys(Keys.ENTER);
driver.findElement(By.id("search-trigger")).sendKeys("Shampoo");
driver.findElement(By.id("search-trigger")).sendKeys(Keys.ENTER);

我想搜索产品,搜索选项在登录页面之前和之后,但在这里我想在登录页面之后进行 我用过

driver.manage().timeouts().implicitlyWait(2, TimeUnit.SECONDS);

但它不起作用,我无法使用

WebElement  “”= driver.findElement(By.id(""));

因为搜索选项在两个页面上 URL 登录后保持不变

根据我的理解,简而言之,您想确保用户在搜索产品之前已经登录。但是您将无法使用 WebElement “”= driver.findElement(By.id(""));

您是否尝试显式等待 username/logout 文本的存在...等等

WebElement element = wait.until(ExpectedConditions.elementIsVisible(By.id(>someid>)));

下面对我有用,在 flipkart 登录后尝试搜索三星:

public static void f() throws InterruptedException
{       
    By signin = By.xpath(".//*[@id='container']/div/header/div[1]/div[1]/div/ul/li[9]/a");
    Thread.sleep(2000);
    By mobile = By.xpath("html/body/div[2]/div/div/div/div/div[2]/div/form/div[1]/input");
    By password = By.xpath("html/body/div[2]/div/div/div/div/div[2]/div/form/div[2]/input");
    By login = By.xpath("html/body/div[2]/div/div/div/div/div[2]/div/form/div[3]/button");
    By myaccount = By.xpath(".//*[@id='container']/div/header/div[1]/div[1]/div/ul/li[8]/a");
    By search = By.xpath(".//*[@id='container']/div/header/div[1]/div[2]/div/div/div[2]/form/div/div[1]/div/input");    
    //geko driver for firefox
    System.setProperty("webdriver.gecko.driver", "path of geckodriver.exe");
    System.setProperty("webdriver.chrome.driver", "path of chromedriver.exe");
    driver = new ChromeDriver();

    driver.get("https://www.flipkart.com/");
    driver.findElement(signin).click();;
    driver.findElement(mobile).sendKeys("xxxxxxxxx");
    driver.findElement(password).sendKeys("xxxxxxxx");
    driver.findElement(login).click();

    WebDriverWait wait = new WebDriverWait (driver, 10);
    wait.until(ExpectedConditions.elementToBeClickable(myaccount));
    driver.findElement(search).sendKeys("samsung");     
}