IJavaScriptExecutor jsExecutor = (IJavaScriptExecutor)driver; jsExecutor.ExecuteScript("$(arguments[0]).change();", selectElement3);//変わらず jsExecutor.ExecuteScript("arguments[0].dispatchEvent(new Event('change'))", selectElement3);//変わらず jsExecutor.ExecuteScript("$(arguments[0]).trigger('select')");//変わらず jsExecutor.ExecuteScript("$(arguments[0]).trigger('change.select2');", selectElement3);//変わらず
driver.FindElement(By.XPath("//*[@id=\"select2-SelectID-results\"]/li[2]")).Click();
//-------一部抜粋----- SelectElement selectElement3 = new SelectElement(driver.FindElement(By.Id("SelectID"))); selectElement3.SelectByText(AfterTenS);//問題なくデータ入力できてる pagewait(); var ClickData = driver.FindElement(By.Id("SelectID"),1000); ClickData.SendKeys(OpenQA.Selenium.Keys.Enter);//なぜかSendKeysがエラーになる【1】 pagewait(); driver.FindElement(By.XPath("//*[@id=\"select2-SelectID-results\"]/li[2]")).Click();// 4 //------------ //待機用 static void pagewait() { //</html>を見つけるまで待機 try { WebDriverWait wait = new WebDriverWait(driver, TimeSpan.FromSeconds(0.01)); IWebElement firstResult = wait.Until(e => e.FindElement(By.XPath("/html"))); } catch (Exception ex) { Console.WriteLine(ex.Message); } }
別のクラス public static class WebDriverExtensions { public static IWebElement FindElement(this IWebDriver driver, By by, int timeoutInSeconds) { if (timeoutInSeconds > 0) { var wait = new WebDriverWait(driver, TimeSpan.FromSeconds(timeoutInSeconds)); return wait.Until(drv => drv.FindElement(by)); } return driver.FindElement(by); } }