1

Since the release of Google Chrome 77, I updated our CI process so headless automated testing is done with:

A simple code who worked perfectly doesn't work anymore, because element.getAttribute('id') returns null instead of the string value of id attribute of the HTML element (which has been found using By.id() !)

I tried such config on Windows and Linux (docker) and the result is the same: getAttribute('id') returns null instead of the HTML element id

Simplified code to reproduce the problem:

String myId = "myInputTypeDateId" ;
WebElement element = (new WebDriverWait(driver, timeout)).until(ExpectedConditions.presenceOfElementLocated(By.id(id)));
String eltId = element.getAttribute("id");
// With chrome 76 & chromedriver 76: returns "myInputTypeDateId"
// With chrome 77 & chromedriver 77: returns null

Additional info:

  • the element related to the problem is an <input type = "date">
  • I am using Aura components framework (Salesforce lightning)

Did someone detected a similar issue with Chrome/Chromedriver 77 ?

Any advice about some workaround ?

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
Nicolas Vuillamy
  • 564
  • 7
  • 14

2 Answers2

1

It seems to be a compatibility bug between chromedriver and Salesforce

It is solved in chromedriver 78 , but the only way to make it work with Chrome 77 seems to use chromedriver 76 with chrome 77

We are several users to ask for a chromedriver 77 patch, but it is not provided yet

More details here: https://bugs.chromium.org/p/chromedriver/issues/detail?id=3103#c6

Nicolas Vuillamy
  • 564
  • 7
  • 14
0

To extract the id attribute as you are trying to invoke getAttribute() from an <input> element, instead of using presenceOfElementLocated() you need to induce WebDriverWait either for the visibility_of_element_located() or element_to_be_clickable() and you can use either of the following Locator Strategies:

  • Using visibilityOfElementLocated():

    System.out.println(new WebDriverWait(driver, 20).until(ExpectedConditions.visibilityOfElementLocated(By.id("myInputTypeDateId"))).getAttribute("id"));
    
  • Using elementToBeClickable():

    System.out.println(new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.id("myInputTypeDateId"))).getAttribute("id"));
    

You can find a detailed discussion in Java Wrapper method for waiting for element to be available for Apache Cordova Webview driven App

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
  • The HTML element is existing in the DOM if it is returned by presenceOfElementLocated. Why should it be mandatory visible or clickable to be able to get it's id attribute ? – Nicolas Vuillamy Sep 25 '19 at 13:46
  • @NicolasVuillamy `presenceOfElementLocated` doesn't guarantees the element will be _visible_ or _interactable_ within the _HTML_. So in your usecase waiting for `visibilityOfElementLocated` would be optimal. However being an `` element it would turn _clickable_ within delta additional span of time. – undetected Selenium Sep 25 '19 at 13:50
  • Sometimes i have to force the scroll to make an element visible & clickable, that's why i need to use the "present" check. But as described in my reply, it's a chromedriver bug ... thanks for your answer ! – Nicolas Vuillamy Sep 26 '19 at 09:21
  • @NicolasVuillamy `elementToBeClickable` would scroll the element before clicking by default. However I have provided a reference discussion. Let me know if it helps. – undetected Selenium Sep 26 '19 at 10:10