C#Selenium SendKeys即使与Javascript执行器一起工作也不起作用
测试找到该元素是因为它没有失败,但无法发送参数 尝试了以下内容:C#Selenium SendKeys即使与Javascript执行器一起工作也不起作用,c#,selenium,xpath,css-selectors,webdriverwait,C#,Selenium,Xpath,Css Selectors,Webdriverwait,测试找到该元素是因为它没有失败,但无法发送参数 尝试了以下内容: driver.FindElement(By.XPath("//input[@type='search']")).Clear(); driver.FindElement(By.XPath("//input[@type='search']")).Click(); IWebElement wb = driver.FindElement(By.XPath("//input[@type='
driver.FindElement(By.XPath("//input[@type='search']")).Clear();
driver.FindElement(By.XPath("//input[@type='search']")).Click();
IWebElement wb = driver.FindElement(By.XPath("//input[@type='search']"));
IJavaScriptExecutor jse = (IJavaScriptExecutor)driver;
jse.ExecuteScript("arguments[0].value='QA Test Automation Developer';", wb);
由于它是一个
标记,您必须为所需的元素导入WebDriverWait to Eclickable()
,并且您可以使用以下任一项:
driver.FindElement(By.XPath("//input[@type='search']")).Clear();
driver.FindElement(By.XPath("//input[@type='search']")).Click();
IWebElement wb = driver.FindElement(By.XPath("//input[@type='search']"));
IJavaScriptExecutor jse = (IJavaScriptExecutor)driver;
jse.ExecuteScript("arguments[0].value='QA Test Automation Developer';", wb);
:css选择器
IWebElement wb = new WebDriverWait(driver, TimeSpan.FromSeconds(20)).Until(ExpectedConditions.ElementToBeClickable(By.CssSelector("input[type='search']"))); wb.Click(); wb.Clear(); wb.SendKeys("QA Test Automation Developer");
:XPath
IWebElement wb = new WebDriverWait(driver, TimeSpan.FromSeconds(20)).Until(ExpectedConditions.ElementToBeClickable(By.XPath("//input[@type='search']"))); wb.Click(); wb.Clear(); wb.SendKeys("QA Test Automation Developer");
使用
IJavaScriptExecutor
- 使用和
:innerHTML
IWebElement wb = new WebDriverWait(driver, TimeSpan.FromSeconds(20)).Until(ExpectedConditions.ElementToBeClickable(By.CssSelector("input[type='search']"))); IJavaScriptExecutor jse = (IJavaScriptExecutor)driver; jse.ExecuteScript("arguments[0].setAttribute('innerHTML','QA Test Automation Developer')", wb);
- 使用和
:textContext
IWebElement wb = new WebDriverWait(driver, TimeSpan.FromSeconds(20)).Until(ExpectedConditions.ElementToBeClickable(By.CssSelector("input[type='search']"))); IJavaScriptExecutor jse = (IJavaScriptExecutor)driver; jse.ExecuteScript("arguments[0].setAttribute('textContext','QA Test Automation Developer')", wb);
参考文献 您可以在以下内容中找到一些相关讨论: