2014-12-02 75 views
1

我有主页,从如果我点击登录,它将被导航到另一个页面(在那里我必须输入登录凭据登录帐户如何使用WebDriver在IE中等待?

没有下面的一段代码,它完全适用于,Firefox和Chrome。但IE它不工作。我认为增加等待,使IE浏览器的问题将解决..

WebDriverWait Test_Wait=new WebDriverWait(driver,10); 
WebElement click=Test_Wait.until(ExpectedConditions.elementIfVisible("login_xpath")); 

我加入这个代码。但我收到错误elementIfVisible改变elementClickable ..如果我更改为elementClickable。它再次发生错误以更改elementIfVisible ..如何解决此问题?

package com.test.testCase; 

import java.io.File; 

import org.openqa.selenium.chrome.ChromeDriver; 
import org.openqa.selenium.firefox.FirefoxDriver; 
import org.openqa.selenium.ie.InternetExplorerDriver; 
import org.openqa.selenium.support.ui.ExpectedCondition; 
import org.openqa.selenium.support.ui.ExpectedConditions; 
import org.openqa.selenium.support.ui.WebDriverWait; 

import com.test.utitlity.clickEvent; 
import com.test.utitlity.globalVariables; 
import com.test.utitlity.switchWindow; 

public class driverManager extends globalVariables{ 
    public static void driverManager(){ 
     browser="ie"; 
     if(browser.equals("ie")){  
     File file = new File("./IEDriverServer.exe");   
     System.setProperty("webdriver.ie.driver", file.getPath()); 
     driver= new InternetExplorerDriver(); 
     } 
     else if (browser.equals("firefox")) 
     { 
      driver=new FirefoxDriver(); 
     } 
     else if (browser.equals("chrome")) 
     { 
      File file= new File("./chromedriver.exe"); 
      System.setProperty("webdriver.chrome.driver", file.getPath()); 
      System.out.println(file.getPath()); 
      driver=new ChromeDriver(); 
     } 
     driver.get("http://www.xxxx.in"); 
     clickEvent.clickAt("login_xpath"); 
     WebDriverWait Test_Wait=new WebDriverWait(driver,10); 
     WebElement click=Test_Wait.until(ExpectedConditions.elementIfVisible("login_xpath")); 
     switchWindow.swindow("TST.");   

    } 
} 

回答

0

从我可以看到的代码中,您正在错误地使用它。 首先,你必须等待元素可见,然后你必须点击它,但是你反过来使用它,因此它不能找到登录按钮,因为它已被点击,你是已经在新页面中。

请使用这样的等待。这将适用于所有浏览器(IE,始终是一种障碍,但它仍然有效):

try{ 
     WebDriverWait Test_Wait=new WebDriverWait(driver,20); 
     WebElement click=Test_Wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("login_xpath"))); 
     clickEvent.clickAt("login_xpath"); 
    }catch(Throwable e){ 
     System.err.println("The login element is not found"); 
    }