2014-02-24 26 views
2

在我的应用程序,当我打开一个页面下拉菜单显示,然后我需要点击继续按钮。问题是下拉需要一些时间来加载值,但在我的代码中点击下拉加载之前。我尝试了隐式等待和thread.sleep,但它有一段时间它的工作和一段时间不起作用。 。 代码:在硒web驱动程序如何写等待下拉等待,然后单击一个按钮

public class Home { 


    public static void main(String[] args) throws IOException, InterruptedException 
    { 
     File file1 = new File("C:\\Selenium\\IEDriverServer_Win32_2.35.3\\IEDriverServer.exe");  System.setProperty("webdriver.ie.driver", file1.getAbsolutePath()); 

    WebDriver driver = new InternetExplorerDriver(); 
     driver.get("http://10.120.13.100/"); 

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

    Thread.sleep(3000); 

    WebElement clickBtn = driver.findElement(By.id("btnHomeProceed")); 
    clickBtn.click(); 

回答

0

使用.until(ExpectedConditions.presenceOfElementLocated(By.id("btnHomeProceed")));

0

新WebDriverWait(驱动程序,30)。直到(ExpectedConditions.visibilityOfElementLocated(By.xpath( “UR的XPath”)))点击();