Facing error message when we defined the webdriver factory in groovy class

246 Views Asked by At

Facing error message when we defined the web driver factory in groovy.

enter image description here

Are there any errors in my code?

Code Snippet:

private static WebDriver driver=null;
@Keyword
    public static void Customized_Start_Time() 
    {
        driver = DriverFactory.getWebDriver();
        Date date = new Date();
        Date yesterday = date.previous()
        SimpleDateFormat customDate;
        customDate = new SimpleDateFormat("d MMM yy"); // Date format could be 03-Sep-20
        String dateOutput = customDate.format(yesterday);
        System.out.println(dateOutput);

        //Date Format is 03-Sep-20
        String[] dateParts=dateOutput.split(" ")
        String res=dateParts[0]
        println dateParts[0]
        
        String beforeXpath="//table[@uitestid='gwt-debug-customFromDatePicker']/tbody/tr[2]/td/table[@class='datePickerDays']/tbody/tr[";
        String AfterXpath="]/td[";
        String LastXpath="]/div"
        boolean flag=false;
        for(int rowNum=2; rowNum<=7;rowNum++)
        {
            for(int colNum=2;colNum<=7;colNum++)
            {
                String dateval=driver.findElement(By.xpath("beforeXpath+rowNum+AfterXpath+colNum+LastXpath")).getText()
                //String dateval =WebUI.getText(findTestObject('beforeXpath+rowNum+AfterXpath+colNum+LastXpath'), FailureHandling.OPTIONAL)
                println (dateval)
                if (dateval.equals(res))
                {
                    driver.findElement(By.xpath("beforeXpath+rowNum+AfterXpath+colNum+LastXpath")).click()
                flag=true;

                    break;
                }
            }
            if(flag)
            {
                break;
            }
        }
1

There are 1 best solutions below

0
On

You need to import Selenium's By library.

Add the following to the top of your script (where the other imports are):

import org.openqa.selenium.By

Or, you can automatically add the missing imports by pressing Ctrl + Shift + O.