Maison  >  Questions et réponses  >  le corps du texte

web - le paramètre d'attente explicite du paramètre Java Selenium n'a aucun effet

J'ai récemment utilisé Selenium comme outil d'automatisation simple, mais lorsque je l'ai testé, j'ai senti que WebDriverWait wait = new WebDriverWait(driver,20); n'avait aucun effet après être entré dans la boîte aux lettres
wait.until(ExpectedConditions.presenceOfElementLocated(By). .id("_mail_component_68_68")).click(); //Ouvre la boîte de réception

    wait.until(ExpectedConditions.presenceOfElementLocated(By.xpath("//*[@sign='letter'][1]"))).click();
    这两段代码明明页面已经有这个元素了,为啥还要等一段时间才进行操作,而且等待是时间也不是固定的,是我电脑问题,很头疼啊,演示的时候非常尴尬的等好长时间。
    selenium 用的3.4
    火狐用的5.3

static {System.setProperty("webdriver.firefox.marionette","C:Program Files (x86)Mozilla Firefoxgeckodriver.exe");} //Pilote du navigateur Firefox

static String url="http://freemail.163.com/"; //L'adresse ouverte par le navigateur

public String openEmail(Stream<String> userNameSream,Stream<String> passwordStream) lève une exception {

long startTime=System.currentTimeMillis();   //获取开始时间  
WebDriver driver = new FirefoxDriver();            //启动浏览器
driver.manage().window().maximize();            //最大化浏览器
WebDriverWait wait = new WebDriverWait(driver,20);
driver.get(url);        //打开连接
driver.switchTo().frame("x-URS-iframe");        //定位到iframe框架中
userNameSream.forEach(e -> driver.findElement(By.name("email")).sendKeys(e));                //输入账号
passwordStream.forEach(p -> driver.findElement(By.name("password")).sendKeys(p));                //输入账号
driver.findElement(By.id("dologin")).click();                                                //点击登录
Thread.sleep(3000);
if(driver.getTitle().contains("网易邮箱")){
    wait.until(ExpectedConditions.presenceOfElementLocated(By.id("_mail_component_68_68"))).click();                     //打开收件箱
    wait.until(ExpectedConditions.presenceOfElementLocated(By.xpath("//*[@sign='letter'][1]"))).click();
    return "成功,从程序开始到打开第一封邮件用时"+(System.currentTimeMillis()-startTime)/1000+"秒";
}else{
    try {
    WebElement loginMsg  = driver.findElement(By.className("ferrorhead"));                 
    return loginMsg.getText();
    }catch(Exception e){
        return "出现其他问题";
    }
}
習慣沉默習慣沉默2702 Il y a quelques jours684

répondre à tous(2)je répondrai

  • 我想大声告诉你

    我想大声告诉你2017-05-27 17:43:08

    WebDriverWait n'exécutera pas de clic tant que tout n'est pas chargé

    répondre
    0
  • 过去多啦不再A梦

    过去多啦不再A梦2017-05-27 17:43:08

    Je ne sais pas pourquoi, mais cela a résolu le problème. J'ai utilisé Firefox et c'est devenu très rapide après être passé à Google.

    répondre
    0
  • Annulerrépondre