简体   繁体   中英

How to implement jquery script in selenium webdriver java

I've created a script as the I want to use in another Selenium WebDriver script:

$function() {
    $("pane1").hide(300);
});

I'm trying to figure out a way to call this script in my Selenium java code.

Calling jQuery functions from Selenium is done exactly the same way as calling any other. However, there are two issues with your code:

  1. You have $function , where you probably mean $(function . If you tried to execute the code in your question as-is you certainly got an error because of this.

  2. Ok, let's say you fix that problem. Now you have a $(function () {...}) call. This is not harmful but it is pointless as you are essentially saying "execute this function when the page has finished its initial load". If you use Selenium the way it is usually used, it won't return control to you until the page has finished its initial load, so there is no reason to wait for the page load.

So:

((JavascriptExecutor) driver).executeScript("$('pane1').hide(300);");

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM