Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/314.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C#Selenium SendKeys即使与Javascript执行器一起工作也不起作用_C#_Selenium_Xpath_Css Selectors_Webdriverwait - Fatal编程技术网

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);
    

参考文献 您可以在以下内容中找到一些相关讨论:


wb.SendKeys(“您想要的任何文本”);没有做任何事情?尝试了上述所有选项,但仍然无效。这是我试图自动化的链接,如果你可以检查它(将是一个关键字搜索和提交,似乎没有找到元素)。