Issue
I use selenium webdriver with C#,
<iframe class="x-component x-fit-item x-component-default" id="component-1105" name="ets_grd_02_IFrame" src="frm_01_master_training_plan.aspx?RID=196&RIU=U&_dc=1641984641351" frameborder="0" style="margin: 0px; width: 718px; height: 535px;"></iframe>
I need to get src attribute of this element. I can locate inside of this iframe and make operations on the form which is located inside that iframe but I can't get src attribute.
Solution
To get the iframe src attribute:
driver.SwitchTo().DefaultContent(); // call this or make sure you are not already switched to this iframe
string iframeSrc = driver.FindElement(By.Xpath("//iframe[contains(@id, 'component-')]")).getAttribute("src")
To interact with the iframe elements:
IWebElement frame = driver.FindElement(By.Xpath("//iframe[contains(@id, 'component-')]"))
driver.SwitchTo().Frame(frame);
// do somethind you like within iframe
driver.SwitchTo().DefaultContent();
Make sure that your target iframe is not placed within some parent iframe. Otherwise, you'll have to first switch to the parent iframe to access the current one.
Answered By - Max Daroshchanka Answer Checked By - Marilyn (PHPFixing Volunteer)
0 Comments:
Post a Comment
Note: Only a member of this blog may post a comment.