Home > Enterprise >  Java Selenium - An invalid or illegal selector was specified
Java Selenium - An invalid or illegal selector was specified

Time:10-26

I wanted to create an method that I can reuse whenever there is a form/textbox on the page and check if it is existing by returning True/False. I created Fields() that I placed on the same Sele class But I am not sure why I am getting the error :

Exception in thread "main" org.openqa.selenium.InvalidSelectorException: invalid selector: An invalid or illegal selector was specified




public boolean Fields(String field, String name) {
    boolean f;
     if (field.equals("textbox")){
            return f= driver.findElement(By.name("'  name  '")).isDisplayed();
           
     }

     return false;

        }



```
`

CodePudding user response:

Instead of this line:

return f= driver.findElement(By.name("'  name  '")).isDisplayed();

Use this:

return f= driver.findElement(By.name('"'  name  '"')).isDisplayed();
  • Related