我无法访问iframe中的元素,我尝试了调用:
IWebElement iframeSwitch = driver.FindElement(By.XPath("//iframe[contains(@id, 'contentIFrame1')and contains (@title, 'Content Area')]"));
driver.SwitchTo().Frame(iframeSwitch);
driver.FindElement(By.Id("hlx_markertemplateid_ledit")).SendKeys("Test");这是表的HTML示例
<table id="hlx_markertemplateid_lookupTable" class="ms-crm-Lookup" cellspacing="0" cellpadding="0" lookupid="hlx_markertemplateid" style="width: 100%; table-layout: fixed;" aria-labelledby="hlx_markertemplateid_c hlx_markertemplateid_w" controlmode="normal">这是td的一个样本。
<td valign="top">
<div id="hlx_markertemplateid_lookupDiv" class="ms-crm-Lookup ms-crm-InlineLookupEdit ms-crm-Hidden-NoBehavior" role="list" ime-mode="auto" tabindex="0" style="width: 0px;">
<ul class="ms-crm-InlineLookupEdit"></ul>
</div>
<label class="ms-crm-Hidden-NoBehavior" for="hlx_markertemplateid_ledit">Marker Template Required</label>
<input id="hlx_markertemplateid_ledit" class="ms-crm-InlineInput ms-crm-InlineLookupEdit" type="text" ime-mode="auto" maxlength="1000" style="ime-mode: auto;">
</td>似乎iframe开关是成功的(因为该调用没有错误),但我无法访问iframe上的任何内容。谢谢你提前提出建议。
发布于 2015-10-13 05:31:16
我可以将文本“测试”发送到iFrame中的输入文本框。我用的是findById。代码是用Java编写的,但是您可以对C#进行相应的修改。
WebElement iframeSwitch = driver.findElement(By.id("contentIFrame1"));
driver.switchTo().frame(iframeSwitch);
System.out.println("Switched");
driver.findElement(By.id("hlx_markertemplateid_ledit")).sendKeys("Test");发布于 2015-10-23 05:03:36
我面临着类似的问题,因此采用了以下方法:
actionObject = new Actions(firefoxDrvrInstance);
actionObject.MoveToElement(find element here).Perform();
firefoxDrvrInstance.FindElement(blah blah).Click();
firefoxDrvrInstance.SwitchTo().Frame(firefoxDrvrInstance.FindElement(blah blah));如果这里有什么不清楚的话请告诉我。
此代码在C#中。
https://sqa.stackexchange.com/questions/15124
复制相似问题