Unable to locate element throwing a org.openqa.selenium.NoSuchElementException in TestNG



  • Am unable to click on element after executing a First test second test showing a org.openqa.selenium.NoSuchElementException . My code Here:

    public class snapooh {
    WebDriver driver; 
    
    @BeforeTest
    public void setup() throws Exception {
         driver =new FirefoxDriver();
         driver.manage().window().maximize();
         driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
         driver.get(" http://abc/sptest/home ");
         System.out.println("Page Launched");
         }
    
    @Test
    public void login(){
        driver.findElement(By.className("loginBtn")).click();
        driver.findElement(By.id("emailaddress")).sendKeys("abc@abc.com");
        driver.findElement(By.id("loginpassword")).sendKeys("87654321");
        driver.findElement(By.id("loginEnter")).click();
      System.out.println("Login button pressed");
    
    }
    @Test
    public void campaign() throws Exception {
        driver.findElement(By.id("usrUtils")).click();;
    
          driver.findElement(By.xpath(" .//*[@id='homeMainContainer']/div[1]/div/div/div[1]/div/ul/li[4]/a")).click();
          driver.findElement(By.className("addItem")).click();
          driver.findElement(By.id("campnNameInput")).sendKeys("Hello");
          driver.findElement(By.id("campnClientNameInput")).sendKeys("Hello");
          driver.findElement(By.id("campnDescInput")).sendKeys("Hello");
        //DateWidget Start date and end date
    
        driver.findElement(By.xpath("  .//*[@id='campnStartInput']")).click();
            WebElement   datepicker = driver.findElement(By.id("ui-datepicker-div"));  
            List rows=  datepicker.findElements(By.tagName("tr"));  
            List columns= datepicker.findElements(By.tagName("td"));  
    
                            for (WebElement cell: columns){  
                                //Select 20th Date   
                                if (cell.getText().equals("16")){  
                                    cell.findElement(By.linkText("16")).click();   
                                        break;
                                }  
                                    }   
    
                            driver.findElement(By.xpath("   .//*[@id='campnEndInput']")).click();
                            WebElement   datepicker1 = driver.findElement(By.id("ui-datepicker-div"));  
                            List rows1=  datepicker1.findElements(By.tagName("tr"));  
                            List columns1= datepicker1.findElements(By.tagName("td"));  
                            for (WebElement cell: columns1){  
                            //Select 20th Date   
                                if (cell.getText().equals("29")){  
                                    cell.findElement(By.linkText("29")).click();   
                                        break;
                                }  
                                    }   
    
        driver.findElement(By.id("createAndUpdateCampaign")).click();
        System.out.println("Campaign created");
    
    }
    
    
        }
    

    My Error Trace here :

     org.openqa.selenium.NoSuchElementException: Unable to locate element:   {"method":"id","selector":"usrUtils"}
     Command duration or timeout: 10.08 seconds
     For documentation on this error, please visit:  http://seleniumhq.org/exceptions/no_such_element.html
     Build info: version: '2.53.0', revision: '35ae25b', time: '2016-03-15 17:00:58'
     System info: host: 'Akshay-PC', ip: '192.168.56.1', os.name: 'Windows 7', os.arch: 'x86', os.version: '6.1', java.version: '1.7.0_80'
     *** Element info: {Using=id, value=usrUtils}
     Session ID: d2fcc233-1bb7-435c-ad51-c8958cba421c
     Driver info: org.openqa.selenium.firefox.FirefoxDriver
    


  • You should wait for page load after click on button,so for that write below code :

    WebElement element;
    Webdriver driver;
    WebDriverWait wait = new WebDriverWait(driver, 100);
    element= wait.until(ExpectedConditions.elementToBeClickable(By.id("usrUtils")));
    


Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2