Why i am getting following error in some circumstances - selenium

I am getting following error message, when i tried below codes. Is it a bug in Selenium?
Sep 19, 2014 10:01:09 PM
org.openqa.selenium.os.UnixProcess$SeleniumWatchDog destroyHarder
INFO: Command failed to close cleanly. Destroying forcefully (v2).
org.openqa.selenium.os.UnixProcess$SeleniumWatchDog#15ae139
Scenario 1:
WebDriver driver=new FirefoxDriver();
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
driver.get("http://www.google.com");
System.out.println(driver.getTitle());
driver.navigate().to("http://www.yahoo.com");
System.out.println(driver.getTitle());
driver.quit();
Scenario 2:
WebDriver driver=new FirefoxDriver();
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
driver.navigate().to("http://www.google.com");
System.out.println(driver.getTitle());
driver.navigate().to("http://www.yahoo.com");
System.out.println(driver.getTitle());
driver.quit();

From the Selenium API:
navigate()
An abstraction allowing the driver to access the browser's history and
to navigate to a given URL.
(emphasis is mine) So unless you somehow populate the history first, your code should fail all the time.

Related

HTMLUnitDriver returning error in Selenium Automation Testing which ChromeDriver doesn't

Aim: To use headless option for selenium testing of login page.(HTMLUnitDriver preferable)
I am trying to automate a login to a site using HTMLUnitDriver.
When I sendKeys to an element, it throws an error.
HtmlUnitDriver driver = new HtmlUnitDriver();
driver.manage().timeouts().implicitlyWait(2, TimeUnit.SECONDS);
driver.get("https://bigData/login.jsp");
WebDriverWait usernameWait = new WebDriverWait(driver, 3);
usernameWait.until(ExpectedConditions.presenceOfElementLocated(By.xpath("//input[#id=\"username\"]")));
driver.findElement(By.xpath("//input[#id=\"username\"]")).sendKeys("admin");
Error:
Exception in thread "main"
org.openqa.selenium.ElementNotInteractableException: You may only
interact with visible elements
I tried the same with ChromeDriver. It works fine! It didn't throw this exception. But I could not use the headless option in it.
ChromeOptions chromeOptions = new ChromeOptions();
chromeOptions.addArguments("--headless");
WebDriver driver = new ChromeDriver(chromeOptions);
returns,
Exception in thread "main" org.openqa.selenium.TimeoutException:
Expected condition failed: waiting for presence of element located by:
By.xpath: //input[#id="username"] (tried for 3 second(s) with 500
milliseconds interval)
Works fine, only when chromeOptions is not defined while initializing chromeDriver.
ChromeOptions chromeOptions = new ChromeOptions();
chromeOptions.addArguments("--headless");
WebDriver driver = new ChromeDriver();
Please guide me what could be these scenarios/suggest an alternative?
As per the documentation, ElementNotInteractableException is the W3C exception which is thrown to indicate that although an element is present on the DOM TREE, it is not in a state that can be interacted with.
Code you can try out is :
HtmlUnitDriver driver = new HtmlUnitDriver(BrowserVersion.CHROME ,true);
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
driver.get("https://bigData/login.jsp");
WebDriverWait usernameWait = new WebDriverWait(driver, 30);
usernameWait.until(ExpectedConditions.visibiltyOfElementLocated(By.xpath("//input[#id=\"username\"]")));
usernameWait.until(ExpectedConditions.elementToBeClickable(By.xpath("//input[#id=\"username\"]")));
driver.findElement(By.xpath("//input[#id=\"username\"]")).sendKeys("admin");
try out this code and let me know the status.

Select a date from Jquery, date picker using selenium webdriver

Go to the Official Website of Jquery https://jqueryui.com/datepicker/
It's not allow be to click on input text even it's have unique id="datepicker" getting an error element not found Exception but when i runs locally by adding jquery date picker it works likes a charm. can somebody help me can't able to figure it out!
2) By using this url i can select anything but it not works with jquery official site as i mentioned above https://jqueryui.com/resources/demos/datepicker/default.html
Below is my actual code that is not getting work
System.setProperty("webdriver.chrome.driver","C:\\ProgramFiles\\chromedriver.exe");
driver=new ChromeDriver();
driver.manage().window().maximize();
driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);
driver.get("https://jqueryui.com/datepicker/");
Thread.sleep(5000);
driver.findElement(By.id("datepicker")).click();
The element with id="datepicker" is within a frame. So we have to switch to the intended frame first, then locate the element and then call the click() method as follows:
System.setProperty("webdriver.chrome.driver", "C:\\Utility\\BrowserDrivers\\chromedriver.exe");
WebDriver driver=new ChromeDriver();
driver.manage().window().maximize();
driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);
driver.get("https://jqueryui.com/datepicker/");
driver.switchTo().frame(driver.findElement(By.xpath("//iframe[#class='demo-frame'][#src='/resources/demos/datepicker/default.html']")));
driver.findElement(By.id("datepicker")).click();
System.out.println("Datepicker Clicked");

Exception in thread "main" java.lang.NullPointerException using WebDriver Driver=new Chrome() and maximize Chrome browser window using selenium script

How to maximize Chrome browser window using selenium script?
This is my code:
package newpackage;
import org.openqa.selenium.WebDriver;
public class MyClass {
public static void main(String[] args) {
WebDriver Driver=new Chrome();
Driver.get("http://www.google.com");
Driver.manage().window().maximize();
}
}
However, I get this error:
Exception in thread "main" java.lang.NullPointerException
at newpackage.MyClass.main(MyClass.java:10)
To work with Selenium 3.4.0 you need to download the latest chromedriver 2.29 from here and update your Google Chrome to latest release of 58.x. Save the chromedriver in your system and provide the absolute path in your code through System.setProperty as below.
Now, the constructor for initializing ChromeDriver and Chrome Browser is as follows:
WebDriver driver = new ChromeDriver();
WebDriver driver = new ChromeDriver(options);
Note: The method is ChromeDriver() but not Chrome() which have caused java.lang.NullPointerException
Finally, to maximize Chrome browser window using selenium script you need to take help of ChromeOptions class as follows:
public static void main(String[] args)
{
System.setProperty("webdriver.chrome.driver", "C:\\path\\to\\chromedriver.exe");
ChromeOptions options = new ChromeOptions();
options.addArguments("start-maximized");
WebDriver driver = new ChromeDriver(options);
driver.navigate().to("https://google.com");
//do your actions
driver.quit();
}
In the script you have written the Driver object is null. Try instantiate the Driver properly by using Chromedriver.
System.setProperty("webdriver.chrome.driver", "c:\\chromedriver.exe");
WebDriver driver = new ChromeDriver();
Driver.get("http://www.google.com");
Driver.manage().window().maximize();
var options = new ChromeOptions();
options.AddArguments("disable-infobars");
options.AddArguments("--start-maximized");
options.AddArguments("--disable-extensions");
var chromeDriver = new ChromeDriver(options);
use driver.manage().window().fullscreen(); instead
It should work.

I am writing a Selenium script in Firefox but I am getting "Untrusted Certificate"

written a code like this
FirefoxProfile profile=new FirefoxProfile();
profile.setAcceptUntrustedCertificates(true);
WebDriver driver=new FirefoxDriver();
driver.get("url");
Not working in firefox how to resolve this one.
You're not creating the driver with the profile - you're creating it with an empty constructor. Try WebDriver driver=new FirefoxDriver(profile);
You can use Selenium WebDriverJS
var WebDriver = require('selenium-webdriver');
var driver = new WebDriver.Builder().withCapabilities(
WebDriver.Capabilities.firefox()
).build();
driver.get('url');

How to automate chrome browser in webdriver? i am getting an error

public void chrome(){
System.setProperty("webdriver.chrome.driver", "/Applications/Google Chrome.app/Contents/MacOS/GoogleChrome"); //Chrome
driver = new ChromeDriver();
driver.get(baseUrl);
System.out.println(driver.getTitle());
driver.close();
driver.quit();
}
running this method throw an error "[4032:519:0701/155158:ERROR:process_singleton_mac.cc(106)] Unable to obtain profile lock."
Download the ChromeDriver.exe from [http://code.google.com/p/selenium/downloads/list] then add the system property as,
System.setProperty("webdriver.chrome.driver", "...\chromedriver.exe");
driver = new ChromeDriver();
Path of chromedriver.exe file should be proper.
hope it will helpful for you.
You need to set the path ChromeDriver before creating ChromeDriver instance
System.setProperty("webdriver.chrome.driver", "/Users/test/ChromeDriverMac/chromedriver");
driver = new ChromeDriver();
driver.get("https://www.google.com");
Download chromedriver from below location
https://code.google.com/p/chromedriver/downloads/list