I am trying to implement NgWebDriver using Selenium Java for angular app.
As per NgWebDriver documentation we have to only pass new NgWebDriver(driver).waitForAngularRequestsToFinish(); driver instance but when I am trying to implement it , I have to cast argument to JavascriptExecutor otherwise its giving error in the syntax.
System.setProperty("webdriver.chrome.driver", "/path/to/chromedriver");
WebDriver d = new ChromeDriver();
NgWebDriver ngdriver = new NgWebDriver((JavascriptExecutor) d);
ngdriver.waitForAngularRequestsToFinish();
When I use this code after casting driver instance as than its not waiting for angular to finish.
Repeater & other functions are working fine of NgWebDriver .
Can anyone please help in in resolving the problem?
Using these versions:
Selenium: 3.3.1
Chrome: 60
Java : 1.8
Maybe you're missing this?
d.manage().timeouts().setScriptTimeout(15, TimeUnit.SECONDS);
You are using
WebDriver d = new ChromeDriver();
instead use the
ChromeDriver driver = new ChromeDriver();
then use the following
NgWebDriver ngWebDriver = new NgWebDriver(driver);
ngWebDriver.waitForAngularRequestsToFinish();
Related
I am setting up a chrome driver with the help of Selenium and Java. I want this driver to be executed headless but I can't find out the way. Can you explain to me what do I need to do?
My code sample:
System.setProperty(CHROME_PROPERTY, LINUX_CHROMEDRIVER_PATH);
driver = new ChromeDriver();
driver.manage().window().maximize();
driver.manage().timeouts().implicitlyWait(DEFAULT_IMPLICITY_TIME, TimeUnit.SECONDS);
System.setProperty(CHROME_PROPERTY, LINUX_CHROMEDRIVER_PATH); // OS and Browser options
ChromeOptions options = new ChromeOptions(); // create options instance
options.addArguments("--headless"); // add an option
driver = new ChromeDriver(options); // create a driver with the specific options instance
You just need to create a ChromeOptions object in which you need to save the options for your own driver.
To add your own options just use this: options.addArguments(); and in the parenthesis insert your option in string mode.
For more details and documentation please also check here:
http://chromedriver.chromium.org/capabilities
I think this is going to work.
I have seen almost everybody using the statement WebDriver driver=new FirefoxDriver(); here we have created an instance of FirefoxDriver class having type as Webdriver;
What if i directly create an instance of FirefoxDriver as FirefoxDriver driver = new FirefoxDriver();
I have gone through many discussion where it is said that Webdriver is an interface. I know what interface is and how it works. I want to know if FirefoxDriver driver = new FirefoxDriver(); is correct when i know that Firefox is the only browser i am gonna use in my selenium script?
As you mentioned in your question that know that Firefox is the only browser you are gonna use in your selenium script then there is no constraint in using the following line of code :
FirefoxDriver driver = new FirefoxDriver();
Here you can find a detailed discussion on What is the difference between ChromeDriver and WebDriver in selenium?
I am working on Selenium WebDriver automation in java programming language. In my test suite that initiates the browser window once and perform all the tests. I want to clear the browser cache before running some tests without restarting the browser. Is there any command/function, that can achieve the purpose? Thanks.
This is what I use in Python:
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
driver = webdriver.Chrome()
driver.get('chrome://settings/clearBrowserData')
driver.find_element_by_xpath('//settings-ui').send_keys(Keys.ENTER)
You can try converting these into Java. Hope this will help! :)
At least in Chrome, I strongly believe that if you go incognito you wont to have to clean up your cookies. You can set your options like following (the :
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
def _options():
options = Options()
options.add_argument('--ignore-certificate-errors')
#options.add_argument("--test-type")
options.add_argument("--headless")
options.add_argument("--incognito")
options.add_argument('--disable-gpu') if os.name == 'nt' else None # Windows workaround
options.add_argument("--verbose")
return options
and call like this:
with webdriver.Chrome(options=options) as driver:
driver.implicitly_wait(conf["implicitly_wait"])
driver.get(conf["url"])
For IE
DesiredCapabilities ieCap = DesiredCapabilities.internetExplorer();
ieCap.setCapability(InternetExplorerDriver.IE_ENSURE_CLEAN_SESSION, true);
For Chrome:
https://code.google.com/p/chromedriver/issues/detail?id=583
To delete cookies:
driver.manage().deleteAllCookies();
The following code is based on #An Khang 's answers. and it is working properly on Chrome 78.
ChromeDriver chromeDriver = new ChromeDriver();
chromeDriver.manage().deleteAllCookies();
chromeDriver.get("chrome://settings/clearBrowserData");
chromeDriver.findElementByXPath("//settings-ui").sendKeys(Keys.ENTER);
return chromeDriver;
WebDriver driver = new ChromeDriver();
driver.manage().deleteAllCookies();
driver.get("chrome://settings/clearBrowserData");
driver.findElement(By.xpath("//settings-ui")).sendKeys(Keys.ENTER);
On Google chrome you can use this script:
driver.get("chrome://settings/clearBrowserData");
JavascriptExecutor jse = (JavascriptExecutor)driver;
WebElement clearData = (WebElement) jse.executeScript("return document.querySelector(\"body > settings-ui\").shadowRoot.querySelector(\"#main\").shadowRoot.querySelector(\"settings-basic-page\").shadowRoot.querySelector(\"#basicPage > settings-section:nth-child(8) > settings-privacy-page\").shadowRoot.querySelector(\"settings-clear-browsing-data-dialog\").shadowRoot.querySelector(\"#clearBrowsingDataConfirm\")");
((JavascriptExecutor)driver).executeScript("arguments[0].click();", clearData);
import org.openqa.selenium.Keys;
you need to import the Keys in newer version and change the last line to findElement by xpath
WebDriver driver = new ChromeDriver();
driver.manage().deleteAllCookies();
driver.get("chrome://settings/clearBrowserData");
driver.findElement(By.xpath("//settings-ui")).sendKeys(Keys.ENTER);
I use selenium-webdriver to automate browser tasks. I used to use "WebDriverWait" for wait an element before using it. Example:
WebDriverWait wait = new WebDriverWait(driver, 5);
wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("frame1")));
This doesn't work anymore with the new version 2.45 of webdriver. The argument for "until" method have been changed and I don't know how to do this now.
Does anyone have the same issue?
Documentation: http://selenium.googlecode.com/git/docs/api/java/org/openqa/selenium/support/ui/FluentWait.html
I use the same 2.45 version of webdriver and haven't experienced any problem yet.
Documentation:
http://selenium.googlecode.com/git/docs/api/java/org/openqa/selenium/support/ui/WebDriverWait.html
Sample that works perfectly to me:
WebDriverWait waitSearchGrid = new WebDriverWait(driver, 10);
waitSearchGrid.until(ExpectedConditions.elementToBeClickable(driver.findElement(By.xpath(".//*[#id='clientSearchResult']/div[1]"))));
How to use this method? What parameter should I pass to "capabilityName" and "value"?
public void setCapability(java.lang.String capabilityName,java.lang.String value);
For Chrome specifically, you can find the capabilities here: https://sites.google.com/a/chromium.org/chromedriver/capabilities-aka-chromeoptions
There is a more general overview of capabilities on the selenium wiki: http://code.google.com/p/selenium/wiki/DesiredCapabilities
Here is an example that maximizes the browser window (for chrome). Enable/Disable the second while running it and see the difference.
ChromeOptions options = new ChromeOptions();
options.addArguments("--start-maximized");
WebDriver driver = new ChromeDriver(options);
driver.get("http://www.google.com");