0

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;
            }
        }
Mate Mrše
  • 7,997
  • 10
  • 40
  • 77
  • What is the actual "error message"? There is no message in the code inspection from your screenshot. Do you face any error when your code is run? Did you `import org.openqa.selenium.By;`? – Konrad Talik Sep 11 '20 at 09:34

1 Answers1

1

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.

Mate Mrše
  • 7,997
  • 10
  • 40
  • 77