I'm trying to click an Element but having some issues. First, there's a pop up window which I'm switching to, which seems to be written ok.
foreach (string handle in _webdriver.WindowHandles)
{
if (!handle.Equals(parentHandle))
{
_webdriver.SwitchTo().Window(handle);
}
}
Then, I'm trying to click an element inside this pop up by this code:
var myElement = wait.Until(x => x.FindElement(By.XPath("//td[@id='firstname_d']/div[@class='ms-crm-Input-Container']/input[@id='firstname']")));
myElement.SendKeys("foo");
I'm getting an Error:
Unable to find element with Xpath
The HTML is as follow:
<tr valign="top">
<td class="ms-crm-FieldLabel-LeftAlign FormSection_CellPadding ms-crm-Field-Recommended" id="firstname_c">
<td id="firstname_d" style="overflow: hidden;" formxmlcolspan="1">
<div class="ms-crm-Input-Container focus" id="firstname_container">
<input tabindex="1010" class="ms-crm-Input ms-crm-Text" id="firstname" style="ime-mode: active;" type="text" maxlength="50" attrformat="text" attrpriv="7" attrname="firstname" req="1" value=""/>
What am I doing wrong?
You can try with the id
driver.FindElement(By.Id("firstname")).SendKeys("foo");
Or using contains
driver.FindElement(By.XPath("//input[contains(@id, 'firstname')]")).SendKeys("foo");
Edit
You can switch to the <iframe>
after the window switch
foreach (string handle in _webdriver.WindowHandles)
{
if (!handle.Equals(parentHandle))
{
_webdriver.SwitchTo().Window(handle);
}
}
_webdriver.SwitchTo().Frame("foo");
_webdriver.FindElement(By.Id("firstname")).SendKeys("foo");
u can write following code and try it Set st=driver.getWindowHandles(); Iterator it= st.iterator(); String parent=t.next();
String child=it.next(); driver.switchTo().frame(child); WebElement ele= driver.findElement(By.id("id="firstname_container")); ele.sendKeys("foo
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.