Search code examples
javascriptjquerycssselenium-webdrivervisual-studio-lightswitch

Can Selenium use buttons from LightSwitch librarz?


Can Selenium use LightSwitch buttons?

At first I had to locate button, the LightSwitch is a button written in CSS, then I will use By.CSSSelector to find. But after I found the button, check which form it is using if on tap/click etc., I found that it is vclick from Jquery library.

Then I wrote code:

js.ExecuteScript("$('.ui-page-active .msls-footer div div:nth-child(2) span').trigger('vclick')");

But even I find the button using selenium yet it is not being clicked. Am I missing something here?

Another thing is that, test will pass correctly, but there is no window opened, after clicking.

Application should switch on click to a new screen, but it really doesn't want to do this move.

Screen of button location:

Screen of button location

After click expected screen:

After click expected screen


Solution

  • Best way to use WebDriverWait instead of Thread.Sleep() as below :-

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

    Hope it will work..:)