0

I'm writing an automated test in Java where I want to send text of an element I need clicked, to be found through that text. Here's the code:

public void selectElement(String elementName, String type, String input){

        By elementToSelect = By.xpath("//*[text()='" + elementName + "']");

        switch (type) {
            case "Photo", "Radio", "Button", "Checkbox" -> {
                driver.findElement(elementToSelect).click();
            }
            case "Edit" -> {
                WebElement edit = driver.findElement(elementToSelect);
                edit.sendKeys(input + org.openqa.selenium.Keys.ENTER);
            }
         
        }
    }

I also tried with this but no such luck:

 WebElement element = (WebElement) ((JavascriptExecutor) driver).executeScript("return $(\":contains('" + elementToSelect + "'):last\").get(0);");
Vlad Nitu
  • 147
  • 1
  • 11
Ema
  • 1
  • 1
  • 1
    Please [edit] your question and add the relevant fragment of the html, for a [mcve]. – Robert Aug 11 '22 at 15:28
  • What happens? Does it produce an error message? – Conal Tuohy Aug 12 '22 at 10:51
  • It produces the following error message: org.openqa.selenium.NoSuchElementException: no such element: Unable to locate element: {"method":"xpath","selector":"//*[text()='Linearmodule']"} – Ema Aug 12 '22 at 10:57

0 Answers0