Member-only story

Selenium moving further

Donald Le
2 min readFeb 24, 2020

--

Today I will go over some advanced tips for how to interact with elements using javascript and combine selenium with other tools.

I. Work with web elements by JavaScript in Selenium

For more details, you can refer to this javascript-selenium-webdriver

In general there are two ways to call javascript execute from selenium:

Execute script:

element = driver.execute_script(script_string, *args)
element = driver.execute_async_script(script_string,*args)

Notes:

If you want to get element value, your script should have ‘return’ like : ‘return arguments[0].shadowRoot’

  1. Find element by javascript:
  • get element by id:
document.getElementByID('{id}')
  • get elements by class name:
document.getElementsByClassName('{className}')
  • get elements by selector:
document.querySelector('{selectorName}')

2.Work with Shadow DOM

For more details about Shadow DOM, you can refer to this shadow dowm

In short, they use Shadow DOM to avoid conflicts by different css, interface style

--

--

Donald Le
Donald Le

Written by Donald Le

A passionate automation engineer who strongly believes in “A man can do anything he wants if he puts in the work”.

No responses yet