skip to Main Content
  1. I can manually inspect and get the xpath of the element.
  2. when I get the xpath of that element, it says 1 of 1. I can create a unique Xpath for the element.
  3. But the selenium cannot find it.

I’m using Waits. So, there is no problem of skipping an element. But, There is also not any iframe in html. still The selenium cannot able to find the element which I’ve create the Xpath for. I provided a screen shot of that issue.screenshot of my issue

This is the code for that:

webEssentials.waitTillElementIsAvailableInDOM(By.xpath("//select[@name='senderId']"));
webEssentials.waitTillElementIsClickable(selectSenderId);
WebElement element = webEssentials.driver.findElement(By.xpath("//select[@name='senderId']"));
        Select select = new Select(element);
        select.selectByIndex(0);

        webEssentials.waitTillElementIsVisible(templateZoho).
                waitTillElementIsClickable(templateZoho);
        WebElement element1 = webEssentials.driver.findElement(By.xpath("//select[@name='template']"));
        Select select1 = new Select(element1);
        select1.selectByIndex(0);
[1]: https://drive.google.com/drive/folders/1rvqESd2SE4cUqGyY7FK-8brI_q_F-6am?usp=sharing This Link having the error log of what I’m getting after the selenium cannot find the element

2

Answers


  1. The desired element is an Angular element. To select one of the from a tag you need to induce WebDriverWait for the elementToBeClickable() and you can use either of the following Locator Strategies:

    • Using name:

      WebElement element = new Select(new WebDriverWait(webEssentials.driver, Duration.ofSeconds(10)).until(ExpectedConditions.elementToBeClickable(By.name("senderId"))));
      
    • Using cssSelector:

      WebElement element = new Select(new WebDriverWait(webEssentials.driver, Duration.ofSeconds(10)).until(ExpectedConditions.elementToBeClickable(By.cssSelector("select[name='senderId']"))));
      
    • Using xpath:

      WebElement element = new Select(new WebDriverWait(webEssentials.driver, Duration.ofSeconds(10)).until(ExpectedConditions.elementToBeClickable(By.xpath("//select[@name='senderId']"))));
      

    References

    You can find a couple of relevant detailed discussions in:

    Login or Signup to reply.
  2. Assuming that your xpath is correct. Then can you please use javaScriptExecutOr method to lcik the lement. Below is the sample code: Also pleas refer link

    Can you please check also-> whether there is any frame available, then you need to switch to that frame first.

     driver.switchTo().frame("frame id");
    
     WebElement ele= driver.findElement(By.xpath(""));        
     js.executeScript(“arguments[0].click();”, ele);
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search