java
  • selenium
  • selenium-webdriver
  • 2016-04-22 112 views 0 likes 
    0

    我一直在玩java的硒,我遇到了一个问题,我不知道。 http://www.legalcontracts.com/contracts/lease-agreement-form/?ldcn=menu+nameorg.openqa.selenium.ElementNotVisibleException点击继续按钮

    从第三页(地址页)要到第四 我能够设置地址:

    这个页面在这里

    @FindBy(xpath="//div[@class=' qd spropertyAddress']/div[@class='ans']/input") 
        private WebElement address; 
    
    public void SetAddress(String addressName){ 
         address.sendKeys(addressName); 
        } 
    

    但是当我试图继续

    @FindBy(xpath="//a[contains(text(),'Continue')]") 
        private WebElement continuebutton; 
    continuebutton.click(); 
    

    我收到一个org.openqa.selenium.ElementNotVisibleException。继续按钮与前一页的编号相同,因此我不确定这是否与它有关。我尝试了很多不同的方法来尝试处理这个问题,但似乎可行的唯一方法是thread.sleep,这不是一个很好的处理方法。

    东西我曾尝试:

    WebDriverWait wait = new WebDriverWait(driver,30); 
         wait.until(ExpectedConditions.elementToBeClickable(continuebutton)); 
         wait.until(ExpectedConditions.elementToBeClickable(continuebutton)); 
         wait.until(ExpectedConditions.presenceOfElementLocated((By) continuebutton)); 
         wait.until(ExpectedConditions.visibilityOfElementLocated((By) continuebutton)); 
    
    
    public void waitForJQuery(WebDriver driver) { 
        (new WebDriverWait(driver, 10)).until(new ExpectedCondition<Boolean>() { 
         public Boolean apply(WebDriver d) { 
          JavascriptExecutor js = (JavascriptExecutor) d; 
          return (Boolean) js.executeScript("return !!window.jQuery && window.jQuery.active == 0"); 
         } 
        }); 
    } 
    
    public void waitForJavaScript(WebDriver driver){ 
        (new WebDriverWait(driver, 10)).until(new ExpectedCondition<Boolean>() { 
         public Boolean apply(WebDriver driver) { 
          return ((JavascriptExecutor)driver).executeScript("return document.readyState").equals("complete"); 
         } 
        } 
    ); 
    
    public void checkPageIsReady(WebDriver driver) { JavascriptExecutor js = (JavascriptExecutor)driver; //Initially bellow given if condition will check ready state of page. 
    
        if (js.executeScript("return document.readyState").toString().equals("complete")){ 
         System.out.println("Page Is loaded."); 
         return; 
         } 
    
        //This loop will rotate for 25 times to check If page Is ready after every 1 second. 
        //You can replace your value with 25 If you wants to Increase or decrease wait time. 
        for (int i=0; i<25; i++){ 
         try { 
          Thread.sleep(1000); } 
         catch (InterruptedException e) {} 
    
         //To check page ready state. 
         if (js.executeScript("return document.readyState").toString().equals("complete")){ 
          break; } } 
        } 
    

    我进来从以前的页面相同的继续进行,但在不同的页面对象:

    @FindBy(xpath="//a[contains(text(),'Continue')]") 
        private WebElement continuebutton; 
    continuebutton.click(); 
    

    能硒是混淆了当前继续按钮,前一个?

    回答

    0

    使用下面的代码:

    driver.findElement(By.cssSelector("div.ans>input#ctl00_Content_ctrlQuestions_ctl194_ctl21_ctl06_ctl01_ctl01_ctl01_in")).click(); 
    
    driver.findElement(By.cssSelector("div.ans>input#ctl00_Content_ctrlQuestions_ctl194_ctl21_ctl06_ctl01_ctl01_ctl01_in")).clear(); 
    
    driver.findElement(By.cssSelector("div.ans>input#ctl00_Content_ctrlQuestions_ctl194_ctl21_ctl06_ctl01_ctl01_ctl01_in")).sendKeys("ur address"); 
    
    Thread.sleep(2000); 
    
    //click on continue button 
    
    driver.findElement(By.cssSelector(" .largeProceedButton.continueButtonnContinueFirst.nContinue")).click(); 
    

    ,而不是使用XPath的就是我上面提到点击继续按钮cssSelector。

    +0

    @eradicator,这工作? – noor

    +0

    我想在我的代码中不使用任何thread.sleeps。如果我使用睡眠一切正常,但它不保证点击将起作用 – eradicator

    +0

    我只是使用它来进行测试......无需使用此等待.....您可以单击继续按钮而无需这等待....你告诉你,我不能点击继续按钮...只需使用我的css路径,点击 – noor

    相关问题