0
  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

  • Can you share the URL of the application if it is public? – Shawn Jun 27 '23 at 12:27
  • Actually, it is private shawn – Deviprasath A Jun 27 '23 at 12:37
  • Have you checked if the "@name" attribute is always present when "select" is rendered? From my experience the "@name" attribute is not reliable when identifying elements with angular. Maybe try with "ng-reflect-name". – Knight Jun 27 '23 at 14:04
  • Ohhh... I'll try, thanks Knight – Deviprasath A Jun 27 '23 at 14:11
  • In your error log it's trying to find element "//iframe[@role='presentation']". As you said if you don't have iframe in your page, may be you should to remove the step in your code where searching this element – Areke Jun 28 '23 at 12:19

2 Answers2

0

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:

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
  • Actually I'm using the waits in another method. webEssentials.waitTillElementIsAvailableInDOM(By.xpath("//select[@name='senderId']")); webEssentials.waitTillElementIsClickable(selectSenderId); Which will do its work before this code that I mentioned. – Deviprasath A Jun 27 '23 at 12:41
  • What will you suggest undected Selenium? I also used this waits in the same method, it is failing in the waits itself. Because, it is waiting for certain time period. But it cannot find the element, so it is failing. – Deviprasath A Jun 27 '23 at 12:44
  • How is `waitTillElementIsAvailableInDOM()` and `waitTillElementIsClickable()` defined? I don't see them in your code trials. Not even the error. What error do you see? – undetected Selenium Jun 27 '23 at 12:56
  • Hello undetected Selenium, I now added the error log of what I'm getting above. Please check it. – Deviprasath A Jun 27 '23 at 13:24
0

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);
arpita biswas
  • 144
  • 1
  • 6