Hi all,
I’m using the browser library and I need to determine an element in a shadow dom to click on it. In this case I tried the following:
${shadow_host_1} = Evaluate JavaScript document.querySelector('${SHADOW_HOST_1_SELECTOR}')
Run Keyword If ${shadow_host_1} == None Fail Could not find shadow host 1
${shadow_root_1} = Evaluate JavaScript arguments[0].shadowRoot ${shadow_host_1}
As ${SHADOW_HOST_1_SELECTOR} I use a css selector like con-app[theme=“XXX”].
When I run the test case I get the following error message:
Unexpected token “querySelector(” while parsing selector “document.querySelector(‘con-app[theme=“XXX”]’)”.
I really tried many variations with the JavaScript code string but it doesn’t seem to have an effect.
Could someone please help and tell me would I did wrong or if there is a better opportunity to do this?
Can you paste the entire xpath. Usually with execute javascript the shadow path won’t work always. You have to use dynamic path. If you can post the xpath code of the element and the html piece of code from where you need to extract it would be helpful. Thanks.
For example:
xpath=//element[@id=‘someid’]/otherelememt//childelement
Hi Sapan,
thanks for your message but I found out that xpath does not work with shadow-dom and I have to use css instead.
As I use the browser library the use of Evaluate JavaScript is not really needed.
yes xpath will not work. But keeping a dynamic xpath will always work for xpath. I had resolved this issue the same way sometime ago. So, if you can paste the entire xpath and source code, we can definitely come up with a dynamic xpath that will always work.