我想测试这个弹出窗口:
但是对于微调器,我得到例外。我尝试了这些代码,但没有使用它们。
Actions componentProportion = new Actions(driver);
componentProportion.SendKesy(Kesy.Control+"a");
componentProportion.SendKeys(editNumber,"2356").Build().Perform();
当我运行此代码时没有任何反应,它也会导致新文本框(显示标题)代码出现问题,但它无法正常工作。
//Edit display title
IWebElement editDt = driver.FindElement(By.XPath("//*[@id='cmp_display_title']"));
editDt.Click();
Thread.Sleep(500);
editDt.SendKeys(Keys.Control + "a");
editDt.SendKeys(Keys.Delete);
Thread.Sleep(500);
editDt.SendKeys("hello");
如果我想使用此代码:
IWebElement editNumber = driver.FindElement(By.CssSelector("something"));
editNumber.Click();
Thread.Sleep(1000);
editNumber.SendKeys(Keys.Control+"a");
我得到了这个例外:
ElementVisibleException:元素不可见
有没有解决这个问题?谢谢你的帮助。
答案 0 :(得分:0)
因此,由于您的元素在框架中,为了能够使用它们,您需要首先切换到该框架(通常按名称)
//Switch to required frame
driver.SwitchTo().Frame("ContentContainer");
// find your elements and do the actions
// This is how you switch to the default page
driver.SwitchTo().DefaultContent();
答案 1 :(得分:-1)
正如我所注意到的,您想要用一些新文本替换显示标题输入文本
为了清除文字,你不需要模拟ctrl + a。
只需使用此代码为文本元素设置新值:
IWebElement editDt = driver.FindElementById("cmp_display_title");
editDt.SendKeys(""); // clears the text
editDt.SendKeys("your new text");