Best Selenium code snippet using org.openqa.selenium.remote.DesiredCapabilities.setJavascriptEnabled
Source:DriverFactoryTest.java
...99 public void testShouldReturnDriverWhereTheMostCapabilitiesMatch_lotsOfRegisteredDrivers() {100 DesiredCapabilities desiredCapabilities = new DesiredCapabilities();101 desiredCapabilities.setBrowserName(FIREFOX);102 desiredCapabilities.setVersion("");103 desiredCapabilities.setJavascriptEnabled(true);104 desiredCapabilities.setPlatform(Platform.ANY);105 assertEquals(FIREFOX, factory.getProviderMatching(desiredCapabilities)106 .getProvidedCapabilities().getBrowserName());107 }108 @Test109 public void testShouldReturnMostRecentlyAddedDriverWhenAllCapabilitiesAreEqual() {110 Capabilities capabilities = new ImmutableCapabilities(BROWSER_NAME, "cheese");111 DriverProvider provider1 = mockDriverProviderFor(capabilities);112 DriverProvider provider2 = mockDriverProviderFor(capabilities);113 factory.registerDriverProvider(provider1);114 factory.registerDriverProvider(provider2);115 assertEquals(provider2, factory.getProviderMatching(capabilities));116 }117 @Test118 public void testShouldConsiderPlatform() {119 DesiredCapabilities windows = new DesiredCapabilities("browser", "v1", Platform.WINDOWS);120 DesiredCapabilities linux = new DesiredCapabilities("browser", "v1", Platform.LINUX);121 DriverProvider windowsProvider = mockDriverProviderFor(windows);122 DriverProvider linuxProvider = mockDriverProviderFor(linux);123 factory.registerDriverProvider(windowsProvider);124 factory.registerDriverProvider(linuxProvider);125 assertEquals(windowsProvider, factory.getProviderMatching(windows));126 assertEquals(linuxProvider, factory.getProviderMatching(linux));127 }128 @Test129 public void testShouldMatchAgainstAnyPlatformWhenRequestingAny() {130 DesiredCapabilities windowsVista = new DesiredCapabilities("browser", "v1", Platform.VISTA);131 DesiredCapabilities windowsXp = new DesiredCapabilities("browser", "v1", Platform.XP);132 DesiredCapabilities anyWindows = new DesiredCapabilities("browser", "v1", Platform.ANY);133 DriverProvider provider = mockDriverProviderFor(windowsVista);134 factory.registerDriverProvider(provider);135 assertEquals(provider, factory.getProviderMatching(windowsVista));136 assertEquals(provider, factory.getProviderMatching(anyWindows));137 assertEquals("Should always get a match if a driver has been registered",138 provider, factory.getProviderMatching(windowsXp));139 }140 @Test141 public void testShouldConsiderJavascriptCapabilities() {142 DesiredCapabilities nojavascript = new DesiredCapabilities("browser", "v1", Platform.LINUX);143 nojavascript.setJavascriptEnabled(false);144 DesiredCapabilities javascript = new DesiredCapabilities("browser", "v1", Platform.LINUX);145 javascript.setJavascriptEnabled(true);146 DriverProvider nojavascriptProvider = mockDriverProviderFor(nojavascript);147 DriverProvider javascriptProvider = mockDriverProviderFor(javascript);148 factory.registerDriverProvider(nojavascriptProvider);149 factory.registerDriverProvider(javascriptProvider);150 assertEquals(nojavascriptProvider, factory.getProviderMatching(nojavascript));151 assertEquals(javascriptProvider, factory.getProviderMatching(javascript));152 }153 @Test154 public void testShouldCallAConstructorTakingACapabilitiesArgInPreferenceToANoArgOne() {155 Capabilities caps = new ImmutableCapabilities(BROWSER_NAME, "example");156 factory.registerDriverProvider(new DefaultDriverProvider(caps, CapabilitiesDriver.class));157 CapabilitiesDriver driver = (CapabilitiesDriver) factory.newInstance(caps);158 assertEquals(caps, driver.getCapabilities());159 }...
Source:PhantomJSTest.java
...76 drivers.stream().forEach(WebDriver::quit);77 }78 public static DesiredCapabilities getDefaultDesiredCapabilities() {79 DesiredCapabilities capabilities = new DesiredCapabilities();80 capabilities.setJavascriptEnabled(true);81 capabilities.setCapability("acceptSslCerts", true);82 capabilities.setCapability("takesScreenshot", true);83 capabilities.setCapability(PhantomJSDriverService.PHANTOMJS_CLI_ARGS, asList("--ignore-ssl-errors=true"));84 LoggingPreferences loggingPreferences = new LoggingPreferences();85 loggingPreferences.enable(LogType.BROWSER, Level.ALL);86 capabilities.setCapability(CapabilityType.LOGGING_PREFS, loggingPreferences);87 return capabilities;88 }89 public static DesiredCapabilities getChromeCapabilities() {90 DesiredCapabilities capabilities = new DesiredCapabilities();91 capabilities.setJavascriptEnabled(true);92 capabilities.setCapability("acceptSslCerts", true);93 capabilities.setCapability("takesScreenshot", true);94 capabilities.setCapability(ChromeDriverService.CHROME_DRIVER_EXE_PROPERTY, asList("--ignore-ssl-errors=true"));95 LoggingPreferences loggingPreferences = new LoggingPreferences();96 loggingPreferences.enable(LogType.BROWSER, Level.ALL);97 capabilities.setCapability(CapabilityType.LOGGING_PREFS, loggingPreferences);98 return capabilities;99 }100}...
Source:WebDriverFactory.java
...29 return new ChromeDriver(chromeDriverCapabilities);30 }31 private static DesiredCapabilities getChromeDesiredCapabilities() {32 DesiredCapabilities desiredCapabilities = new DesiredCapabilities();33 desiredCapabilities.setJavascriptEnabled(true);34 desiredCapabilities.setCapability(CapabilityType.SUPPORTS_FINDING_BY_CSS, true);35 desiredCapabilities.setCapability(CapabilityType.TAKES_SCREENSHOT, true);36 ChromeOptions chromeOptions = new ChromeOptions();37 chromeOptions.addArguments("start-maximized");38 desiredCapabilities.setCapability(ChromeOptions.CAPABILITY, chromeOptions);39 return desiredCapabilities;40 }41}...
Source:BaseIntegration.java
...13public class BaseIntegration {14 public static final int TIMEOUT = 10;15 public static FirefoxDriver firefoxDriver() {16 DesiredCapabilities capabilities = firefox();17 capabilities.setJavascriptEnabled(true);18 FirefoxDriver driver = new FirefoxDriver(capabilities);19 driver.manage().window().maximize();20 return driver;21 }22 public static ChromeDriver chromeDriver() {23 File file = null;24 if (SystemUtils.IS_OS_LINUX) {25 file = new File("src/test/resources/driver/linux/chromedriver");26 }27 if (SystemUtils.IS_OS_WINDOWS) {28 file = new File("src/test/resources/driver/windows/chromedriver.exe");29 }30 if (SystemUtils.IS_OS_MAC) {31 file = new File("src/test/resources/driver/mac/chromedriver");32 }33 if (file == null) {34 throw new RuntimeException("ChromeDriver is not supported by your operating system");35 }36 System.setProperty("webdriver.chrome.driver", file.getAbsolutePath());37 DesiredCapabilities capabilities = chrome();38 capabilities.setJavascriptEnabled(true);39 ChromeDriver driver = new ChromeDriver(capabilities);40 driver.manage().window().maximize();41 return driver;42 }43 public static WebDriver mobileDriver() {44 return new RemoteWebDriver(android());45 }46}...
Source:BrowserToCapabilities.java
...19 caps = DesiredCapabilities.firefox();20 break;21 case htmlunit:22 caps = DesiredCapabilities.htmlUnit();23 caps.setJavascriptEnabled(false);24 break;25 case htmlunit_js:26 caps = DesiredCapabilities.htmlUnit();27 caps.setJavascriptEnabled(true);28 break;29 case ie:30 caps = DesiredCapabilities.internetExplorer();31 break;32 case opera:33 caps = DesiredCapabilities.opera();34 break;35 case phantomjs:36 caps = DesiredCapabilities.phantomjs();37 break;38 case safari:39 caps = DesiredCapabilities.safari();40 break;41 case ipad:...
Source:BrowserCapabilities.java
...11 switch (browser) {12 case CHROME:13 capabilities = DesiredCapabilities.chrome();14 capabilities.setAcceptInsecureCerts(true);15 capabilities.setJavascriptEnabled(true);16 capabilities.setCapability(CapabilityType.UNEXPECTED_ALERT_BEHAVIOUR,17 UnexpectedAlertBehaviour.IGNORE);18 return capabilities;19 case FIREFOX:20 capabilities = DesiredCapabilities.firefox();21 capabilities.setAcceptInsecureCerts(true);22 capabilities.setJavascriptEnabled(true);23 capabilities.setCapability(CapabilityType.UNEXPECTED_ALERT_BEHAVIOUR,24 UnexpectedAlertBehaviour.IGNORE);25 return capabilities;26 default:27 capabilities = DesiredCapabilities.chrome();28 capabilities.setAcceptInsecureCerts(true);29 capabilities.setJavascriptEnabled(true);30 capabilities.setCapability(CapabilityType.UNEXPECTED_ALERT_BEHAVIOUR,31 UnexpectedAlertBehaviour.IGNORE);32 return capabilities;33 }34 }35}...
Source:RemoteTest.java
...16 public static WebDriver getDefaultRemoteDriver(String remoteUrl) throws Exception{17 WebDriver driver=null;18 try {19 DesiredCapabilities capabilities = DesiredCapabilities.firefox();20 capabilities.setJavascriptEnabled(true);21 //capabilities.setBrowserName("chrome");22 23 URL url = new URL(remoteUrl);24 driver = new RemoteWebDriver(url, capabilities);25 driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);26 driver.get("http://www.baidu.com");27 28 DesiredCapabilities capabilities2 = DesiredCapabilities.chrome();29 capabilities2.setJavascriptEnabled(true);30 capabilities2.setBrowserName("chrome");31 URL url2 = new URL(remoteUrl);32 driver = new RemoteWebDriver(url2, capabilities2);33 driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);34 driver.get("http://www.baidu.com");35 } catch (Exception e) {36 e.printStackTrace();37 }38 return driver;39 }40}...
Source:RemoteEngine.java
...20 DesiredCapabilities capabilities;21 URL url = new URL(remoteUrl);22 if (browserName.equalsIgnoreCase("Firefox")) {23 capabilities = DesiredCapabilities.firefox();24 capabilities.setJavascriptEnabled(true);25 driver = new RemoteWebDriver(url, capabilities);26 } else if (browserName.equalsIgnoreCase("Chrome")) {27 capabilities=DesiredCapabilities.chrome();28 capabilities.setJavascriptEnabled(true);29 capabilities.setBrowserName("chrome");30 driver = new RemoteWebDriver(url, capabilities);31 } else if (browserName.equalsIgnoreCase("IE")) {32 //IE33 }34 35 driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);36 } catch (Exception e) {37 // TODO: handle exception38 }39 return driver;40 }41}...
setJavascriptEnabled
Using AI Code Generation
1import org.openqa.selenium.remote.DesiredCapabilities;2import org.openqa.selenium.remote.RemoteWebDriver;3import org.openqa.selenium.WebDriver;4import org.openqa.selenium.By;5import org.openqa.selenium.WebElement;6import org.openqa.selenium.JavascriptExecutor;7import java.net.URL;8public class DesiredCapabilitiesTest {9public static void main(String[] args) throws Exception {10DesiredCapabilities capabilities = DesiredCapabilities.firefox();11capabilities.setJavascriptEnabled(true);12WebElement element = driver.findElement(By.name("q"));13element.sendKeys("Cheese!");14element.submit();15System.out.println("Page title is: " + driver.getTitle());16driver.quit();17}18}
setJavascriptEnabled
Using AI Code Generation
1 DesiredCapabilities capabilities = DesiredCapabilities.chrome();2 capabilities.setJavascriptEnabled(true);3 WebDriver driver = new RemoteWebDriver(capabilities);4 DesiredCapabilities capabilities = DesiredCapabilities.chrome();5 capabilities.setCapability("javascriptEnabled", true);6 WebDriver driver = new RemoteWebDriver(capabilities);7 ChromeOptions options = new ChromeOptions();8 options.addArguments("javascriptEnabled");9 DesiredCapabilities capabilities = DesiredCapabilities.chrome();10 capabilities.setCapability(ChromeOptions.CAPABILITY, options);11 WebDriver driver = new RemoteWebDriver(capabilities);12 FirefoxOptions options = new FirefoxOptions();13 options.addPreference("javascriptEnabled", true);14 DesiredCapabilities capabilities = DesiredCapabilities.firefox();15 capabilities.setCapability(FirefoxOptions.FIREFOX_OPTIONS, options);16 WebDriver driver = new RemoteWebDriver(capabilities);17 InternetExplorerOptions options = new InternetExplorerOptions();18 options.setCapability("javascriptEnabled", true);19 DesiredCapabilities capabilities = DesiredCapabilities.internetExplorer();20 capabilities.setCapability(InternetExplorerOptions.CAPABILITY, options);21 WebDriver driver = new RemoteWebDriver(capabilities);22 EdgeOptions options = new EdgeOptions();23 options.setCapability("javascriptEnabled", true);24 DesiredCapabilities capabilities = DesiredCapabilities.edge();25 capabilities.setCapability(EdgeOptions.CAPABILITY, options);26 WebDriver driver = new RemoteWebDriver(capabilities);27 OperaOptions options = new OperaOptions();28 options.setCapability("javascriptEnabled", true);29 DesiredCapabilities capabilities = DesiredCapabilities.operaBlink();30 capabilities.setCapability(OperaOptions.CAPABILITY, options);31 WebDriver driver = new RemoteWebDriver(capabilities);
setJavascriptEnabled
Using AI Code Generation
1public class DesiredCapabilitiesTest {2 public static void main(String[] args) throws Exception {3 DesiredCapabilities capabilities = new DesiredCapabilities();4 capabilities.setJavascriptEnabled(true);5 WebElement element = driver.findElement(By.name("q"));6 element.sendKeys("Cheese!");7 element.submit();8 System.out.println("Page title is: " + driver.getTitle());9 driver.quit();10 }11}
setJavascriptEnabled
Using AI Code Generation
1package com.edureka.selenium;2import org.openqa.selenium.WebDriver;3import org.openqa.selenium.firefox.FirefoxDriver;4import org.openqa.selenium.remote.DesiredCapabilities;5public class DisableJavascript {6public static void main(String[] args) {7System.setProperty("webdriver.gecko.driver", "/home/edureka/Downloads/geckodriver");8DesiredCapabilities capabilities = DesiredCapabilities.firefox();9capabilities.setJavascriptEnabled(false);10WebDriver driver = new FirefoxDriver(capabilities);11System.out.println("Page title is: " + driver.getTitle());12driver.quit();13}14}15package com.edureka.selenium;16import org.openqa.selenium.WebDriver;17import org.openqa.selenium.firefox.FirefoxDriver;18public class DisableJavascript {19public static void main(String[] args) {20System.setProperty("webdriver.gecko.driver", "/home/edureka/Downloads/geckodriver");21FirefoxProfile profile = new FirefoxProfile();22profile.setPreference("javascript.enabled", false);23WebDriver driver = new FirefoxDriver(profile);24System.out.println("Page title is: " + driver.getTitle());25driver.quit();26}27}28package com.edureka.selenium;29import org.openqa.selenium.WebDriver;30import org.openqa.selenium.firefox.FirefoxDriver;31public class DisableJavascript {32public static void main(String[] args) {33System.setProperty("webdriver.gecko.driver", "/home/edureka/Downloads/geckodriver");34FirefoxProfile profile = new FirefoxProfile();35profile.setPreference("javascript.enabled", false);36WebDriver driver = new FirefoxDriver(profile);37System.out.println("Page title is: " + driver.getTitle());38driver.quit();39}40}41package com.edureka.selenium;42import org.openqa.selenium.WebDriver;43import org.openqa.selenium.firefox.FirefoxDriver;44public class DisableJavascript {45public static void main(String[] args) {46System.setProperty("webdriver.gecko.driver", "/home/edureka/Downloads/geckodriver");47FirefoxProfile profile = new FirefoxProfile();48profile.setPreference("javascript.enabled", false);
setJavascriptEnabled
Using AI Code Generation
1import org.openqa.selenium.WebDriver;2import org.openqa.selenium.remote.DesiredCapabilities;3import org.openqa.selenium.firefox.FirefoxDriver;4public class EnableJavascript {5 public static void main(String[] args) {6 DesiredCapabilities capabilities = DesiredCapabilities.firefox();7 capabilities.setJavascriptEnabled(true);8 WebDriver driver = new FirefoxDriver(capabilities);9 }10}
setJavascriptEnabled
Using AI Code Generation
1package com.qtpselenium.app.salesforce.testcases;2import java.net.MalformedURLException;3import java.net.URL;4import java.util.concurrent.TimeUnit;5import org.openqa.selenium.By;6import org.openqa.selenium.WebDriver;7import org.openqa.selenium.remote.DesiredCapabilities;8import org.openqa.selenium.remote.RemoteWebDriver;9import org.testng.annotations.Test;10public class DesiredCapabilitiesExample {11 WebDriver driver;12 public void testDesiredCapabilities() throws MalformedURLException {13 DesiredCapabilities capability = DesiredCapabilities.firefox();14 capability.setJavascriptEnabled(true);15 driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);16 driver.findElement(By.name("q")).sendKeys("Selenium");17 driver.findElement(By.name("btnG")).click();18 driver.quit();19 }20}21package com.qtpselenium.app.salesforce.testcases;22import java.net.MalformedURLException;23import java.net.URL;24import java.util.concurrent.TimeUnit;25import org.openqa.selenium.By;26import org.openqa.selenium.WebDriver;27import org.openqa.selenium.remote.DesiredCapabilities;28import org.openqa.selenium.remote.RemoteWebDriver;29import org.testng.annotations.Test;30public class DesiredCapabilitiesExample {31 WebDriver driver;32 public void testDesiredCapabilities() throws MalformedURLException {33 DesiredCapabilities capability = DesiredCapabilities.firefox();34 capability.setJavascriptEnabled(true);35 capability.setCapability("proxy", "
LambdaTest’s Selenium 4 tutorial is covering every aspects of Selenium 4 testing with examples and best practices. Here you will learn basics, such as how to upgrade from Selenium 3 to Selenium 4, to some advanced concepts, such as Relative locators and Selenium Grid 4 for Distributed testing. Also will learn new features of Selenium 4, such as capturing screenshots of specific elements, opening a new tab or window on the browser, and new protocol adoptions.
Upgrading From Selenium 3 To Selenium 4?: In this chapter, learn in detail how to update Selenium 3 to Selenium 4 for Java binding. Also, learn how to upgrade while using different build tools such as Maven or Gradle and get comprehensive guidance for upgrading Selenium.
What’s New In Selenium 4 & What’s Being Deprecated? : Get all information about new implementations in Selenium 4, such as W3S protocol adaption, Optimized Selenium Grid, and Enhanced Selenium IDE. Also, learn what is deprecated for Selenium 4, such as DesiredCapabilites and FindsBy methods, etc.
Selenium 4 With Python: Selenium supports all major languages, such as Python, C#, Ruby, and JavaScript. In this chapter, learn how to install Selenium 4 for Python and the features of Python in Selenium 4, such as Relative locators, Browser manipulation, and Chrom DevTool protocol.
Selenium 4 Is Now W3C Compliant: JSON Wireframe protocol is retiring from Selenium 4, and they are adopting W3C protocol to learn in detail about the advantages and impact of these changes.
How To Use Selenium 4 Relative Locator? : Selenium 4 came with new features such as Relative Locators that allow constructing locators with reference and easily located constructors nearby. Get to know its different use cases with examples.
Selenium Grid 4 Tutorial For Distributed Testing: Selenium Grid 4 allows you to perform tests over different browsers, OS, and device combinations. It also enables parallel execution browser testing, reads up on various features of Selenium Grid 4 and how to download it, and runs a test on Selenium Grid 4 with best practices.
Selenium Video Tutorials: Binge on video tutorials on Selenium by industry experts to get step-by-step direction from automating basic to complex test scenarios with Selenium.
LambdaTest also provides certification for Selenium testing to accelerate your career in Selenium automation testing.
Get 100 minutes of automation test minutes FREE!!