简体   繁体   中英

How to extract or select Particular Date and Time on remainder Element in selenium web driver

As I am doing testing in my web application with selenium webdriver java, in that one element is remainder-on, I tried with my code, but it showing error:

The Exception:

Exception in thread "main" org.openqa.selenium.NoSuchElementException: Unable to locate element: .btn-flat\ For documentation on this error, please visit: http://seleniumhq.org/exceptions/no_such_element.html 

But I want to select particular date and time, please help me in a code

java eclipse selenium

driver.findElement(By.id("time")).click();

driver.findElement(By.className("dtp-btn-ok")).click();

Thread.sleep(2000);

driver.findElement(By.id("th-12")).click();

Thread.sleep(3000);

driver.findElement(By.className("btn-flat ")).click();


// driver.findElement(By.id("note")).sendKeys("Be Alert Every Time");

        //driver.findElement(By.className("green")).click();

package com.s3sales.demo;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.interactions.Actions;
import org.openqa.selenium.support.ui.Select;


public class Leads {

    public static void main(String[] args) throws InterruptedException {

        WebDriver driver=new FirefoxDriver();

        driver.get("http://sssamriddhisales.com/crm");

        Thread.sleep(2000);

        driver.findElement(By.id("userName")).sendKeys("admin");

        Thread.sleep(2000);

        driver.findElement(By.id("password")).sendKeys("admin123");     

        Thread.sleep(2000); 

        driver.findElement(By.className("btn-success")).click();

        Thread.sleep(1000);

         WebElement element = driver.findElement(By.linkText("Leads"));

         Thread.sleep(1000);

         Actions action = new Actions(driver);

        action.moveToElement(element).moveToElement(driver.findElement(By.cssSelector("[data-id='leads']"))).click().build().perform();

        Thread.sleep(2000);

        driver.findElement(By.id("newLead")).click();

        Thread.sleep(1000);

        driver.findElement(By.id("custFirstName")).sendKeys("SUBBA");

        Thread.sleep(1000);

        driver.findElement(By.id("custLastName")).sendKeys("RAO");

        Thread.sleep(2000);

        Select service=new Select(driver.findElement(By.id("custService")));

        service.selectByVisibleText("Loan Against Gold");

        Thread.sleep(2000);

        driver.findElement(By.id("custContactNo")).sendKeys("7799445588");

        Thread.sleep(1000);

        driver.findElement(By.id("custEmail")).sendKeys("mymail2subbarao@gmail.com");

        Thread.sleep(1000);

        driver.findElement(By.id("isCust")).click();

        Thread.sleep(2000);

        Select branch=new Select(driver.findElement(By.id("custBranch")));

        branch.selectByVisibleText("gopal shop");

        Thread.sleep(1000);

        driver.findElement(By.id("addressLine1")).sendKeys("6-1-138/J , Shali Bandda");

        Thread.sleep(1000);

        driver.findElement(By.id("addressLine2")).sendKeys("Charminar , Hyderabad");

        Thread.sleep(1000);

        Select state=new Select(driver.findElement(By.id("stateName")));

        state.selectByVisibleText("Telangana");

        Thread.sleep(2000);

        Select district=new Select(driver.findElement(By.id("districtName")));

        district.selectByVisibleText("Ranga Reddy");

        Thread.sleep(1000);

        Select area=new Select(driver.findElement(By.id("areaName")));

        area.selectByVisibleText("Uppal");

        Thread.sleep(1000);

        Select addType=new Select(driver.findElement(By.id("addressType")));

        addType.selectByVisibleText("Home");

        Thread.sleep(1000);

        driver.findElement(By.id("isAddPer")).click();

         Thread.sleep(1000);

         Select status=new Select(driver.findElement(By.id("status")));

         status.selectByVisibleText("Follow up");

         Thread.sleep(1000);

         //remainder-on in Leads Module

        driver.findElement(By.id("time")).click();

        driver.findElement(By.className("dtp-btn-ok")).click();

        Thread.sleep(2000);

        driver.findElement(By.id("th-12")).click();

        Thread.sleep(3000);

        driver.findElement(By.className("btn-flat ")).click();


        // driver.findElement(By.id("note")).sendKeys("Be Alert Every Time");

        //driver.findElement(By.className("green")).click();

    }

}

The Exception:

Exception in thread "main" org.openqa.selenium.NoSuchElementException: Unable to locate element: .btn-flat\ For documentation on this error, please visit: http://seleniumhq.org/exceptions/no_such_element.html

You should be using WebDriverWait not sleep!

This will help you with your error too...

WebDriverWait wait = new WebDriverWait(webDriver, 30);
wait.until(ExpectedConditions.elementToBeClickable(By.className("btn-flat"))).click();

EDIT:

With that been said... it may be just a syntax error here... you have in you locator By.className("btn-flat ") with a space at the end of the className... in my answer, I have changed that to By.className("btn-flat") ... feel free to change it back.

EDIT2:

After looking at the site as I suspected the locators are not correct...

The iFrame that opens is not an iFrame yet it behaves like one...

To overcome this I have changed the locators to XPath's as follows:

(By.XPATH, "//div[@class='dtp']//*[@class='dtp-btn-ok btn btn-flat']")

The class='dtp' is the iFrame and whatever follows is the XPath to the element!

Hope this helps you!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM