PHPUnit Selenium2 Error on getting current input text value - selenium

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.

Related

Selenium - Unable to Create a remote session. [FF 53.0.2 + Geckodriver 0.16 + Selenium 3.4]

I can able to see the FF[53.0.2] opened. But, I am getting an "error Unable to create new remote session". Could any one help out?
Environment :
Windows 7 64 bit
FF - 53.0.2 (32bit)
Selenium 3.4
Geckdriver 0.16 and 0.16.1[win 32]
Problem :
Unable to create a new remote session. But, driver initiated the FF [blank browser].
System.setProperty("webdriver.gecko.driver", System.getProperty("user.dir")+"\\src\\Drivers\\geckodriver-‌v0.16.0-win32\\gecko‌​driver.exe");
DesiredCapabilities caps2 = DesiredCapabilities.firefox();
caps2.setBrowserName("firefox"‌​);
caps2.setPlatform(‌​org.openqa.selenium.‌​Platform.WINDOWS);
dr‌​iver1= new RemoteWebDriver(new URL(node),caps2);
Actual output :
org.openqa.selenium.SessionNotCreatedException: Unable to create new remote session. desired capabilities = Capabilities [{marionette=true, browserName=firefox, moz:firefoxOptions={binary=Optional.empty, args=[], legacy=null, logLevel=null, prefs={}, profile=null}, version=, platform=VISTA}], required capabilities = Capabilities [{moz:firefoxOptions={binary=Optional.empty, args=[], legacy=null, logLevel=null, prefs={}, profile=null}}]
Build info: version: '3.3.1', revision: '5234b32', time: '2017-03-10 09:04:52 -0800'
System info: host: 'XXXXXXXXX', ip: 'XXX.XXX.XX.XXX', os.name: 'Windows 7', os.arch: 'amd64', os.version: '6.1', java.version: '1.8.0_65'
Driver info: driver.version: FirefoxDriver
Build info: version: 'unknown', revision: '5234b32', time: '2017-03-10 09:00:17 -0800'
System info: host: 'XXXXXXXXX', ip: 'XXX.XXX.XX.XXX', os.name: 'Windows 7', os.arch: 'amd64', os.version: '6.1', java.version: '1.8.0_65'
Driver info: driver.version: FirefoxDriver
Why don't you try replacing this
System.setProperty("webdriver.gecko.driver", System.getProperty("user.dir")+"\\src\\Drivers\\geckodriver-‌​v0.16.0-win32\\gecko‌​driver.exe");
With this:
System.setProperty("webdriver.gecko.driver", "explicit path to your geckodriver);
I got this issue resolved.While setting up a node, i gave the configuration as geckodriver-‌​v0.16.1-win32. Irrespective of setting other properties, it didn't change.Simple one, but i took a long way to explore. Anyways, thank you guys.

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...

Stale element reference Selenium Web driver

I tried to implement a test suite using selenium.
While writing the automated script, the driver is able to enter the data using xpath. In the result I can see the value entered into the text box, but while saving the page throws error that data is not entered in to the column(Stale element Exception).
To solve this, I tried to move the focus out and get back to the column and enter the data again. Still I am getting the same kind of error.
Error Message:
Element not found in the cache - perhaps the page has changed since it
was looked up For documentation on this error, please visit:
http://seleniumhq.org/exceptions/stale_element_reference.html Build
info: version: '2.47.1', revision: '411b314', time: '2015-07-30
03:03:16' System info: host: 'HQ04HQQTP006', ip: '10.10.220.164',
os.name: 'Windows 7', os.arch: 'x86', os.version: '6.1', java.version:
'1.8.0_66' Driver info: driver.version: unknown Command duration or
timeout: 8.17 seconds For documentation on this error, please visit:
http://seleniumhq.org/exceptions/stale_element_reference.html Build
info: version: '2.47.1', revision: 'unknown', time: '2015-07-30
11:02:44' System info: host: 'HQ-GRID-001', ip: '10.10.1.206',
os.name: 'Windows 7', os.arch: 'amd64', os.version: '6.1',
java.version: '1.8.0_65' Driver info:
org.openqa.selenium.remote.RemoteWebDriver Capabilities
[{applicationCacheEnabled=true, rotatable=false, handlesAlerts=true,
databaseEnabled=true, version=40.0.3, platform=WINDOWS,
nativeEvents=false, acceptSslCerts=true,
webdriver.remote.sessionid=b95bec47-70a6-4c88-bbc0-e38c9d56aff0,
webStorageEnabled=true, locationContextEnabled=true,
browserName=firefox, takesScreenshot=true, javascriptEnabled=true,
cssSelectorsEnabled=true}] Session ID:
b95bec47-70a6-4c88-bbc0-e38c9d56aff0
Please let me know if I am not clear in the question, I will try to explain it more.
I have two tips for you to try here:
After doing sendKeys do sendKeys(Keys.TAB) on same element or click some other text box. The point of doing this here is There might be some fields that update data after you enter something into other field. Example : Actual column.
Now after this is done and you see the data entered correctly, you need to give some time to your save button in case if it was disabled initially. In this case, use:
WebDriverWait wait = new WebDriverWait(driver, 10);
WebElement element = wait.until(ExpectedConditions.elementToBeClickable(By.YOUR LOCATOR));
Here I would recommend that you mention the locator and Not a previously identified element, since refreshing etc. may corrupt previously identified elements.

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

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’ : ‘/’})

Error in Selenium while running androidwebdriver

I run the Sample Selenium code from http://code.google.com/p/selenium/wiki/AndroidDriver on my htc sensation android device. But while Running it as Android JUnit test from ecclipse, i get this stack trace. Unable to understand it. I am new to Selenium, so any help or suggestion would help me most.
Thanks
org.openqa.selenium.NoSuchElementException: Could not find element with name: q
For documentation on this error, please visit: http://seleniumhq.org/exceptions/no_such_element.html
Build info: version: 'unknown', revision: 'unknown', time: 'unknown'
System info: os.name: 'Linux', os.arch: 'armv7l', os.version: '2.6.35.13-g2299e28', java.version: '0'
Driver info: driver.version: AndroidWebDriver
at org.openqa.selenium.android.AndroidWebElement.lookupElement(AndroidWebElement.java:341)
at org.openqa.selenium.android.AndroidWebElement.access$1(AndroidWebElement.java:330)
at org.openqa.selenium.android.AndroidWebElement$FindByImpl.findElementByName(AndroidWebElement.java:295)
at org.openqa.selenium.android.AndroidWebDriver$AndroidFindBy.findElementByName(AndroidWebDriver.java:457)
at org.openqa.selenium.By$ByName.findElement(By.java:286)
at org.openqa.selenium.android.AndroidWebDriver.findElement(AndroidWebDriver.java:393)
at simple.app.test.SimpleGoogleTest.testGoogleWorks(SimpleGoogleTest.java:32)
at java.lang.reflect.Method.invokeNative(Native Method)
at android.test.InstrumentationTestCase.runMethod(InstrumentationTestCase.java:204)
at android.test.InstrumentationTestCase.runTest(InstrumentationTestCase.java:194)
at android.test.ActivityInstrumentationTestCase2.runTest(ActivityInstrumentationTestCase2.java:186)
at android.test.AndroidTestRunner.runTest(AndroidTestRunner.java:169)
at android.test.AndroidTestRunner.runTest(AndroidTestRunner.java:154)
at android.test.InstrumentationTestRunner.onStart(InstrumentationTestRunner.java:529)
at android.app.Instrumentation$InstrumentationThread.run(Instrumentation.java:1584)