2017-10-17 93 views
0

我有下面這段代碼顯示:我怎樣才能使硒等到下一個頁面加載相同的URL,並且具有相同的字段

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("")); 

的搜索選項是兩個頁面 上和網址仍然登錄也

回答

0

按我的理解後相同,總之,要確保用戶搜索一個產品之前已經登錄。然而,你將無法使用WebElement「」= driver.findElement(By.id(「」));

你嘗試明確等待的用戶名/註銷文本的存在...等

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");  
} 
相關問題