I am having a method which returns the web driver for firefox, while running the tests they are getting failed throwing the error
"org.openqa.selenium.WebDriverException: Invalid byte 10, offset 76."
On searching I couldn't find anything related to error.
Have pasted the code as well.
System.setProperty("webdriver.gecko.driver", "/Users/sdabral/Downloads/geckodriver");
final DesiredCapabilities capabilities = new DesiredCapabilities(DesiredCapabilities.firefox());
FirefoxProfile profile = new FirefoxProfile();
profile.setPreference("security.mixed_content.block_active_content",
false); //Required for browser mixed contents
capabilities.setCapability(FirefoxDriver.PROFILE, profile);
final WebDriver wd = new RemoteWebDriver(capabilities);
return wd;
The path to geckodriver is correct as referenced other answers related to WebDriverException.
Related
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.
when I do the following line
driver = new RemoteWebDriver(new Uri("http://localhost:4444/wd/hub"), oCapabilities, TimeSpan.FromSeconds(timeout));
Firefox generate the error "Secure Connection Failed". I'm guessing the proxy is blocked, how can I prevent it?
I'm following this page without success:
http://www.seleniumhq.org/docs/04_webdriver_advanced.jsp
1-) Had to update selenium drivers.
2-) Also that firefox was always opening as if it was the first use. to prevent this:
FirefoxProfile profile = new FirefoxProfile();
profile.SetPreference("browser.startup.homepage_override.mstone", "ignore");
DesiredCapabilities capabilities = DesiredCapabilities.Firefox();
capabilities.SetCapability(FirefoxDriver.ProfileCapabilityName, profile.ToBase64String()); // profile MUST be converted to this type
driver = new RemoteWebDriver(new Uri(remoteAddress), capabilities, TimeSpan.FromSeconds(timeout));
Could someone please help me with the following issue.
While I'm trying to initialize a browser I get the 'os error' exception.
var option = new FirefoxOptions();
option.IsMarionette = true;
var driver = new FirefoxDriver(option);
var b = new Browser(driver); // Throws an exception with a message - 'os error'
The screenshot of the exception
Plese note, the path to wires.exe is added to the system PATH. Selenium, wires, firefox are of the latest versions. I have tried running using firefox-stable and firefox-developer editions.
Thanks.
So I ran into the 'os error' issue when I was trying to get Marionette working. The source of the issue in my case was I was trying to use some NuGet package called 'Mozilla Firefox Webdriver 0.6.0.1' which I believe had a very old version of the (now called) geckodriver.exe.
I downloaded the latest version of the driver from here https://github.com/mozilla/geckodriver/releases
renamed to wires.exe and put in my working directory
then I had to initiate the driver using the following code.
FirefoxDriverService service = FirefoxDriverService.CreateDefaultService();
service.FirefoxBinaryPath = #"C:\Program Files (x86)\Mozilla Firefox\firefox.exe";
Driver = new FirefoxDriver(service);
The way you initated the driver was giving me an entity not found exception.
Hope this helps
Maybe DesiredCapabilities would work.
DesiredCapabilities capabilities = DesiredCapabilities.Firefox();
capabilities.SetCapability("marionette", true);
var driver = new FirefoxDriver(capabilities);
I'm trying to use headless webkit of PhantomJs for opening google.com through selenium webdriver but when I execute the code system throws an error. phantomJs.exe is placed in E directory. Please help me resolve this issue.
public static void main(String[] args) throws Exception {
DesiredCapabilities caps = new DesiredCapabilities();
caps.setJavascriptEnabled(true);
caps.setCapability(PhantomJSDriverService.PHANTOMJS_EXECUTABLE_PATH_PROPERTY, "E:\\phantomjs.exe");
WebDriver driver = new PhantomJSDriver();
driver.get("http://www.google.com");
}
Error:
Exception in thread "main" java.lang.IllegalStateException: The path to the driver executable must be set by the phantomjs.binary.path capability/system property/PATH variable; for more information, see https://github.com/ariya/phantomjs/wiki. The latest version can be downloaded from http://phantomjs.org/download.html
at com.google.common.base.Preconditions.checkState(Preconditions.java:197)
at org.openqa.selenium.phantomjs.PhantomJSDriverService.findPhantomJS(PhantomJSDriverService.java:236)
at org.openqa.selenium.phantomjs.PhantomJSDriverService.createDefaultService(PhantomJSDriverService.java:181)
at org.openqa.selenium.phantomjs.PhantomJSDriver.(PhantomJSDriver.java:104)
at org.openqa.selenium.phantomjs.PhantomJSDriver.(PhantomJSDriver.java:94)
at multidrivers.main(multidrivers.java:35)
Exception in thread "main" java.lang.IllegalStateException: The path to the driver executable must be set by the phantomjs.binary.path capability/system property/PATH variable;
The above issue is due to the driver not being initialized with the DesiredCapabilities object:
WebDriver driver = new PhantomJSDriver();
Updating the code as below should solve your issue:
WebDriver driver = new PhantomJSDriver(caps);
Let me know if you have any queries.
I am trying to upload a file using Safari Driver.
Here is my code:
DesiredCapabilities browserCapabillities = DesiredCapabilities.safari();
RemoteWebDriver driver = new SafariDriver(browserCapabillities);
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
driver.get("myAppURL");
WebElement upload = driver.findElementByXPath("//input[#id='fileElementId']");
RemoteWebElement webElement = ((RemoteWebElement) upload);
LocalFileDetector detector = new LocalFileDetector();
webElement.setFileDetector(detector);
File f = detector.getLocalFile("myFilePath");
upload.sendKeys(f.getAbsolutePath()); // Generating exception:
// org.openqa.selenium.WebDriverException: Unknown command: uploadFile
driver.findElement(By.id("uploadButton")).click();
Only thing that is working for me right now is AppleScript. Thanks to Using AppleScript to choose a file in Safari. But with Apple Script I had to keep my machine unlocked.
I feel LocalFileDetector is a better solution as I would like to run my tests even when the machine is locked.
I am not sure whether the following helps ?
driver.setFileDetector(new LocalFileDetector()); // I am getting
// org.openqa.selenium.WebDriverException: Setting the file detector only
// works on remote webdriver instances obtained via RemoteWebDriver
Change
RemoteWebDriver driver = new SafariDriver(browserCapabillities);
to
RemoteWebDriver driver = new RemoteWebDriver(urlofhub,browserCapabillities);
Refer this post for an example code.