0

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;

        }



```
`
newb03
  • 1
  • 2

1 Answers1

0

Instead of this line:

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

Use this:

return f= driver.findElement(By.name('"'+ name +'"')).isDisplayed();
AbiSaran
  • 2,538
  • 3
  • 9
  • 15
  • Hey thanks! i am no longer getting the exception error but on "tf = driver.findElement(By.name('"'+ name +'"')).isDisplayed();" the "driver" has this error java.lang.Error: Unresolved compilation problem: driver cannot be resolved – newb03 Oct 26 '22 at 02:10
  • If it works, accept this as the answer – AbiSaran Oct 26 '22 at 02:11