Unable to switch to iframe and access object in iframe in a SHADOW DOM

38 views
Skip to first unread message

Farhan

unread,
Oct 2, 2020, 6:17:15 PM10/2/20
to Selenium Users

I was able to get to iframe in the shadow DOM using the code below, I need to switch to iframe in order to access the objects.Not sure How to do it ..?



public void shadowFrame() {

WebElement sroot = find(By.xpath("//adv-sch[@class='adv sch' and @id='is_new']"));

WebElement shadowRoot = expandRootElement(sroot);


WebElement myiframe =ele.findElement(By.tagName("iframe"));

//This is where I am stuck - I need to switch to iframe and the object I need to access is in iframe.

Can you help How to switch to iframe ..? driver.switchto().iframe(0) will not work

findElement(By.xpath("//input[@placeholder='Search' and @type='text']")) .sendKeys("Last Name");


}


private WebElement expandRootElement(WebElement element) {


WebElement ele = (WebElement) ((JavascriptExecutor) getDriver()).executeScript("return arguments[0].shadowRoot",

element);

Reply all
Reply to author
Forward
0 new messages