Scripts for Selenium Chrome and htmlUnit - selenium

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

Related

Cannot find firefox binary in PATH. Make sure firefox is installed. OS appears to be: WIN10

I am getting following error. Can you advice.
`Exception in thread "main" org.openqa.selenium.WebDriverException: Cannot find firefox binary in PATH. Make sure firefox is installed. OS appears to be: WIN10
Build info: version: '3.13.0', revision: '2f0d292', time: '2018-06-25T15:32:14.902Z'
System info: host: 'CTSAUS-LT-641', ip: '10.243.111.75', os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '1.8.0_172'
Driver info: driver.version: FirefoxDriver
at org.openqa.selenium.firefox.FirefoxBinary.<init>(FirefoxBinary.java:116)
at java.util.Optional.orElseGet(Unknown Source)
at org.openqa.selenium.firefox.FirefoxOptions.getBinary(FirefoxOptions.java:217)
at org.openqa.selenium.firefox.FirefoxDriver.toExecutor(FirefoxDriver.java:161)
at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:125)
at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:103)
at newpackage.MyClass.main(MyClass.java:11)`
Do as error message tells you: Make sure firefox is installed.
Then check out, if it is configured properly, i.e. firefox.exe is in a directory which appears in your PATH environment variable. You can check it out with typing echo %PATH% in your command line.
See where Fiurefox is installed for example by right-clicking on your Firefox desktop icon and then checking "Properties" dialog to see where it is installed.
If for example firefox.exe is in directory "C:\Program Files (x86)\Mozilla Firefox" then this directory has to appear in the (semicolon separated) list of the PATH varaible.

Unable to load selenium chrome driver from maven class path

i am running selenium for chrome and need to open google page. i am using testng and i have my chrome driver in the path \src\test\resources. i use jdk 1.8 and windows 64
i use the below code and i am not able to load successsfully
ClassLoader classLoader = getClass().getClassLoader();
File file = new File(classLoader.getResource("chromedriver-2.27.exe").getFile());
String path=file.getAbsolutePath();
System.setProperty("webdriver.chrome.driver",path);
WebDriver driver = new ChromeDriver();
driver.get("www.google.com");
i get error
org.openqa.selenium.WebDriverException: Timed out waiting for driver server to start.
Build info: version: '3.3.1', revision: '5234b325d5', time: '2017-03-10 09:10:29 +0000'
System info: host: 'NANSARI', ip: '172.18.240.141', os.name: 'Windows 7', os.arch: 'amd64', os.version: '6.1', java.version: '1.8.0_121'
Driver info: driver.version: ChromeDriver
Please advise.
Try it this way and see if it works -
Put the ChromeDriver outside the project directory, say - C:\Selenium_Drivers
Code -
System.setProperty("webdriver.chrome.driver","C:\\Selenium_Drivers\\chromedriver.exe");
WebDriver driver = new ChromeDriver();
driver.get("www.google.com");
Please use the latest version of Selenium, ChromeDriver and Chrome

Selenide tests hang in Firefox

I'm experiencing a problem running Selenide tests in Firefox version 46. When tests run separately everything works fine. But when I run all test methods in class it hangs on the following step:
addons.productaddons INFO sending request to: https://aus5.mozilla.org/update/3/GMP/46.0/20160421124000/WINNT_x86_64-msvc-x64/en-US/release/Windows_NT%206.1.1.0%20(x64)/default/default/update.xml
addons.productaddons INFO Completed downloading document
addons.productaddons INFO Downloading from https://cdmdownload.adobe.com/firefox/win/x64/primetime_gmp_win_x64_gmc_40673.zip to C:\Users\hunar_letsko\AppData\Local\Temp\tmpaddon
addons.productaddons INFO Downloading from http://ciscobinary.openh264.org/openh264-win64-0410d336bb748149a4f560eb6108090f078254b1.zip to C:\Users\hunar_letsko\AppData\Local\Temp\tmpaddon
addons.manager INFO Skipping background update check
DeferredSave.extensions.json DEBUG Save changes
DeferredSave.extensions.json DEBUG Starting timer
DeferredSave.extensions.json DEBUG Starting write
DeferredSave.extensions.json DEBUG Write succeeded
One more note: when test method are running more than 3 hours of hanging it fails with connection timeout:
org.openqa.selenium.WebDriverException: java.net.SocketTimeoutException: Read timed out
Build info: version: '3.0.0', revision: '350cf60', time: '2016-10-13 10:48:57 -0700'
System info: host: 'EPBYMINW2815', ip: '10.6.9.56', os.name: 'Windows 7', os.arch: 'amd64', os.version: '6.1', java.version: '1.8.0_92'
Driver info: driver.version: RemoteWebDriver
selenide.url: app_url"
selenide.baseUrl: http://localhost:8080
at org.openqa.selenium.remote.service.DriverCommandExecutor.execute(DriverCommandExecutor.java:91)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:601)
at org.openqa.selenium.remote.RemoteWebDriver.get(RemoteWebDriver.java:322)
at org.openqa.selenium.remote.RemoteWebDriver$RemoteNavigation.to(RemoteWebDriver.java:902)
at com.codeborne.selenide.impl.Navigator.navigateToAbsoluteUrl(Navigator.java:69)
at com.codeborne.selenide.impl.Navigator.open(Navigator.java:31)
at com.codeborne.selenide.Selenide.open(Selenide.java:81)
at com.codeborne.selenide.Selenide.open(Selenide.java:55)
at
where app_url is my application's url.
Thanks for any help in advance, guys!
You need to downgrade Selenide. Selenide 4.0 works bad with Firefox.

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.

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)