0

I have a simple <a> element which is inside an iframe. I want to click it and if I first try to use getAccessibleName() method on it and then click it I got StaleElementReferenceException. If I try to direct click the element there isn't any problems. At the same time I am able to use methods like getText() or getLocation(), but If I try call getAccessibleName() then unknow error is provided and 32000 is the code. After that the element becoms stale and can't be used anymore.

Where is the problem and why this method provide such an error? I'm using this method to create something like a detailed report for test execution and is important for me. I don't have any other problems and I using this method all the time and this is the first case with errors? If someone else is having an issue like this please let me know, will appreciate all comments and suggestions.

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
  • Is it possible to provide a code and a link to the site? – Ivan Feb 18 '23 at 13:52
  • Please clarify your specific problem or provide additional details to highlight exactly what you need. As it's currently written, it's hard to tell exactly what you're asking. – undetected Selenium Feb 18 '23 at 13:59
  • Unfortunately, I can't provide a link to the site, it's internal for the company. Will try to add some pseudo-code to add more context later. What I am interested in is why I get an exception when calling getAccessibleName() on the web element. How could I protect myself in case of such an error? Has anyone else had a case of getting problems with this method given that the web element is available and can be operated on? – Ivan Nikolov Feb 18 '23 at 14:51

1 Answers1

0

getAccessibleName()

getAccessibleName() gets result of a Accessible Name and Description Computation for the Accessible Name of the WebElement.

Ideally before extracting the Accessible Name you have to induce WebDriverWait for the visibilityOfElementLocated() and you can use the following solution:

driver.get("https://www.selenium.dev/");
System.out.println(new WebDriverWait(driver, Duration.ofSeconds(10)).until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//h2[text()='Getting Started']"))).getAccessibleName());

Console Output:

Getting Started
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352