Selenium 可以使用 Light Switch 库中的按钮吗?
Can Selenium use buttons from LightSwitch librarz?
Selenium 可以使用 LightSwitch 按钮吗?
一开始我要定位按钮,LightSwitch是写在CSS里的一个按钮,然后我就用By.CSSSelector找。
但是在我找到按钮后,检查它使用的是哪种形式 if on tap/click 等,我发现它是 Jquery 库中的 vclick
。
然后我写了代码:
js.ExecuteScript("$('.ui-page-active .msls-footer div div:nth-child(2) span').trigger('vclick')");
但即使我找到了使用硒的按钮,也没有被点击。
我在这里遗漏了什么吗?
另一件事是,测试会正确通过,但点击后没有window打开。
应用程序应该在单击时切换到新屏幕,但它确实不想执行此操作。
按钮位置的屏幕:
点击预期屏幕后:
使用 WebDriverWait
而不是 Thread.Sleep()
的最佳方法如下:-
IWebElement el = (IWebElement)js.ExecuteScript("return $ ('.ui-page-active .msls-footer div div:nth-child(2)')[0]");
WebDriverWait wait = new WebDriverWait(Driver, TimeSpan.FromSeconds(20));
wait.Until(ExpectedConditions.ElementToBeClickable(el)).Click();
希望它会起作用..:)
Selenium 可以使用 LightSwitch 按钮吗?
一开始我要定位按钮,LightSwitch是写在CSS里的一个按钮,然后我就用By.CSSSelector找。
但是在我找到按钮后,检查它使用的是哪种形式 if on tap/click 等,我发现它是 Jquery 库中的 vclick
。
然后我写了代码:
js.ExecuteScript("$('.ui-page-active .msls-footer div div:nth-child(2) span').trigger('vclick')");
但即使我找到了使用硒的按钮,也没有被点击。 我在这里遗漏了什么吗?
另一件事是,测试会正确通过,但点击后没有window打开。
应用程序应该在单击时切换到新屏幕,但它确实不想执行此操作。
按钮位置的屏幕:
点击预期屏幕后:
使用 WebDriverWait
而不是 Thread.Sleep()
的最佳方法如下:-
IWebElement el = (IWebElement)js.ExecuteScript("return $ ('.ui-page-active .msls-footer div div:nth-child(2)')[0]");
WebDriverWait wait = new WebDriverWait(Driver, TimeSpan.FromSeconds(20));
wait.Until(ExpectedConditions.ElementToBeClickable(el)).Click();
希望它会起作用..:)