Unable to add cookie using Selenium::Remote::Driver - selenium

I am unable to add a cookie using this module.
Even when I use a simple example ..
$driver->add_cookie('foo','bar','/','my_server',0);
I get error :
(Error while executing command: An unknown server-side error occurred while processing the command.: given 'cookie' parameters are invalid (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 20 milliseconds
Build info: version: '2.24.1', revision: '17205', time: '2012-06-19 17:28:14'
System info: os.name: 'Windows 7', os.arch: 'amd64', os.version: '6.1', java.version: '1.7.0_13'
Driver info: driver.version: RemoteWebDriver
Session ID: cdbf4aca4034937573ca0cea4a9e5977 at C:/workspace/ST/t/TestCl.pm line 21.)
I also tried spoofing a real looking domain name in my hosts file and pointing it to the server. However it was not helpful at all.
Plz help .

For anyone reading this the cookies have to be in a dictionary as such:
add_cookie({‘name’ : ‘foo’, ‘value’ : ‘bar’, ‘path’ : ‘/’})

Related

NoSuchWindow error when I try to use Facebook sign in using RSelenium

I am trying to log in to a site that uses facebook login, using RSelenium.
I can enter my email and password and click login, but then returns a "NoSuchWindow" error.
Is this because the Facebook login tab automatically closes?
How can I prevent this error?
rm(list = ls())
library(RSelenium)
library(keyring)
library(rvest)
library(magrittr)
# Start Selenium Session
#docker run -d -p 4445:4444 selenium/standalone-firefox
remDr <- RSelenium::remoteDriver(remoteServerAddr = "localhost",
port = 4445L,
browserName = "firefox")
remDr$open()
remDr$navigate("https://www.furimawatch.net/signin/")
remDr$findElement('xpath', '//*[#id="btnTermsAgree"]')$clickElement()
remDr$findElement('xpath', '//*[#id="btnFacebookSignin"]')$clickElement()
remDr$switchToWindow(setdiff(remDr$getWindowHandles(), remDr$getCurrentWindowHandle())[[1]])
remDr$findElement('xpath', '//*[#id="email"]')$sendKeysToElement(list("email"))
remDr$findElement('xpath', '//*[#id="pass"]')$sendKeysToElement(list("password"))
remDr$findElement('xpath', '//*[#id="loginbutton"]')$clickElement()
remDr$screenshot(display = TRUE)
This returns the following error:
Selenium message:Browsing context has been discarded
Build info: version: '4.3.0', revision: 'a4995e2c09*'
System info: host: '0d8a70d5e451', ip: '172.17.0.2', os.name: 'Linux', os.arch: 'amd64', os.version: '5.10.104-linuxkit', java.version: '11.0.15'
Driver info: driver.version: unknown
Error: Summary: NoSuchWindow
Detail: A request to switch to a different window could not be satisfied because the window could not be found.
class: org.openqa.selenium.NoSuchWindowException
Further Details: run errorDetails method
You are facing NoSuchWindow error as the Browsing context has been discarded which is due to the incompatibility between the versions of the binary executables (WebDriver & Browser).
This symptom is reflected as in:
Driver info: driver.version: unknown
which implies the webdriver version can't be recognized due to incompatibility.
Following the compatibility matrix will address the issue.

org.openqa.selenium.WebDriverException: unknown error: cannot determine loading status from unknown error: missing or invalid 'entry.level'

I am getting an weird error for a specific URL. I am running selenium webdriver script using TestNG, eclipse, and Maven.
My test:
#TestNG
{
MyPage mypg = new MyPage(driver);
mypage.openURL();
}
Calls this method:
public void openURL(){
//driver.get("http://www.site1.com/");
//driver.get("http://www.site2.com/");
driver.get("http://www.site3.com/");
System.out.println("Opened the URL");
}
When I run my test, site1 and site2 works just fine. It opens the URLS and then prints the message.
However, when I run my test for site3, it opens site3.com and then status stays in running mode. It never prints the message "opened the URL" and running mode(red button) stays on. Then I see the below error. I am not sure why it is acting this way for site3. It works for site1 and site2. I updated the maven project. I restarted Eclipse. It did not help. Please advise.
org.openqa.selenium.WebDriverException: unknown error: cannot
determine loading status from unknown error: missing or invalid
'entry.level' (Session info: chrome=63.0.3239.132) (Driver info:
chromedriver=2.29.461591
(62ebf098776g1772160f391d75e589dc567915b233),platform=Windows NT
140.10.155063 x86_64) (WARNING: The server did not provide any stacktrace information) Command duration or timeout: 1.29 seconds
Build info: version: '3.4.0', revision: 'unknown', time: 'unknown'
System info: host: 'L-XP79550-A8198', ip: '1x2.1xx.1.1xx', os.name:
'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version:
'1.8.0_131' Driver info: org.openqa.selenium.chrome.ChromeDriver
I have a testng test. When I run the script, it opens URL and print message just fine. It d
After adding the dependencies to pom.xml, site3.com worked. Still not sure why site1 and 2 worked without these dependencies but site3 did not work. At least now it worked.
maven-compiler-plugin
maven-surefire-plugin
webdrivermanager
selenium-chrome-driver

Selenium - Remote Control - Unable to create new service: ChromeDriverService

When I start the selenium test with gird (Remote control), I see this ERROR on log. The browser is not able to open. I did check and tried the following things:
Stop and start both hub and node. I use the default commands to start hub and node. From command prompt, I see that the node was registered successfully and ready to use
Clean Eclipse Project at Project>Clean
Restart my PC
Disconnect VPN
Use latest selenium standalone 3.6; chromedriver.exe
Check the path to chromedriver.exe
Use my PC as hub and another PC as node
Please note that this issue only happen if I run the test with grid (remote control). The test can run normally locally.
2017-10-20 15:23:37,805 ERROR [Log] Class Utils | Method OpenBrowser | Exception desc : Unable to create new service: ChromeDriverService
Build info: version: '3.6.0', revision: '6fbf3ec767', time: '2017-09-27T16:15:40.131Z'
System info: host: 'MY-PC', ip: 'xx.xxx.xxx.xx', os.name: 'Windows 7', os.arch: 'amd64', os.version: '6.1', java.version: '1.8.0_121'
Driver info: driver.version: unknown
Command duration or timeout: 319 milliseconds
Please give me advice in this case. Thanks!

Scripts for Selenium Chrome and htmlUnit

I have some Java scripts for Chrome browser and now I want to run the scripts in htmlUnit. I think the scripts are the same for both, but I got some error when running in htmlUnit? why? So basically which actions (click()? isDisplayed()? etc.) only in Browser test but not in headless tests? and general documents about this difference? Thanks
######### Seems css may have problem here but work OK in Chrome ##############
Exception in thread "main" org.openqa.selenium.NoSuchElementException:
Returned node was not an HTML element For documentation on this error,
please visit: http://seleniumhq.org/exceptions/no_such_element.html
Build info: version: '2.45.0', revision: '32a636c', time: '2015-03-05
22:01:35' System info: host: 'FGS-CIT-2758', ip: '192.168.200.201',
os.name: 'Windows 7', os.arch: 'x86', os.version: '6.1', java.version:
'1.8.0_40' Driver info: driver.version: HtmlUnitDriver at
org.openqa.selenium.htmlunit.HtmlUnitDriver.findElementByCssSelector(HtmlUnitDriver.java:1002)
at org.openqa.selenium.By$ByCssSelector.findElement(By.java:426) at
org.openqa.selenium.htmlunit.HtmlUnitDriver$5.call(HtmlUnitDriver.java:1648)
at
org.openqa.selenium.htmlunit.HtmlUnitDriver$5.call(HtmlUnitDriver.java:1)
at
org.openqa.selenium.htmlunit.HtmlUnitDriver.implicitlyWaitFor(HtmlUnitDriver.java:1302)
at
org.openqa.selenium.htmlunit.HtmlUnitDriver.findElement(HtmlUnitDriver.java:1644)
at
org.openqa.selenium.htmlunit.HtmlUnitDriver.findElement(HtmlUnitDriver.java:550)
at com.ATIP400Suite.CH_ATIP40.mainCheck(CH_ATIP40.java:461) at
com.ATIP400Suite.CH_ATIP40.main(CH_ATIP40.java:58)
Line461 =
driver.findElement(By.cssSelector("span.icon-meter.enlargeIcon")).isDisplayed()
Did you enable javascript in HtmlUnitDriver?
If yes, before click check ExpectedConditions:
presenceOfElementLocated (if you are not sure that an element is present on the DOM)
elementToBeClickable
good luck...

PHPUnit Selenium2 Error on getting current input text value

I'm having strange behavior while trying to get input text value:
$this->byXPath( "//input[contains(#id, '_rule_1_display_times')]" )->value();
Error output:
PHPUnit_Extensions_Selenium2TestCase_WebDriverException : GET
/session/3ef42f7e-f5f5-459d-92e2-6377c6f05e61/element/4/value Build
info: version: '2.45.0', revision: '5017cb8', time: '2015-02-26
23:59:50' System info: host: 'vytautas', ip: '127.0.1.1', os.name:
'Linux', os.arch: 'amd64', os.version: '3.13.0-49-generic',
java.version: '1.7.0_75' Driver info: driver.version: unknown
It's strange cause I can set value to this input without any problem:
$this->byXPath( "//input[contains(#id, '_rule_1_display_times')]" )->value(8);
Any ideas what's wrong with getting current input text value?
Value gives you the current value of the field vs attribute(value) that gives you the original value.
It was asked here: Difference between Element.value and Element.getAttribute("value")
So I'm guessing your current value is simply empty/not set.