Element gets identified , click not working inside iframe

62 views
Skip to first unread message

Sundari Subramanian

unread,
Apr 29, 2024, 10:46:48 PM4/29/24
to Selenium Users
I have a structure like
<Open shadow root>
<iframe>
    <select>
        <options for select>

I did  a shadow root and switched to the frame. Although i could identify the select with xpath/css selector, am not able to click the element options. Click does not throw error but click does not work as well.

When i print on the elements after switching to frame, i see the select being listed and even options being listed. I am able to get text of the options. Only the click does not seem to work. Send keys enter throws an error.

sunnd...@gmail.com

unread,
Apr 30, 2024, 1:29:40 PM4/30/24
to Selenium Users
has anyone faced similar issue?. Any input would be helpful to me.

Thanks

Sir Jo

unread,
May 1, 2024, 5:47:11 AM5/1/24
to Selenium Users
it's hard to find a solution, can you post a complete page source so we can try it ?

Adrian

unread,
May 1, 2024, 4:52:48 PM5/1/24
to Selenium Users
Hi, 

Cheers,
Adrian.

Mahadevayya M K

unread,
May 2, 2024, 5:51:10 AM5/2/24
to Selenium Users
Hello,

Please find the below code which access the shadow root:
Steps:
1) First locate the parent tag of shadow root
2) Use that parentOfShadowRoot element to access the tags inside it
3) Use elementInsideShadowRoot instance inorder to access the all tags that comes under root


//ds header is class inside which I have shadow root element
WebElement parentOfShadowRoot = driver.findElement(By.xpath("//ds-header"));
System.out.println(parentOfShadowRoot.getAttribute("id")); // returning __nuxt

//locating .ds-logo which is inside shadow root
WebElement elementInsideShadowRoot = (WebElement) ((JavascriptExecutor) driver)
.executeScript("return arguments[0].shadowRoot.querySelector('.ds-logo')", parentOfShadowRoot);

if (elementInsideShadowRoot != null) {
//performing action to test
String val = elementInsideShadowRoot.getAttribute("class");
System.out.println(val);
} else {
System.out.println("Element inside shadow root not found.");
}


Thanks!
Reply all
Reply to author
Forward
0 new messages