I want to find some elements from an JavaScript based website. I use Java and Selenium. Everything works fine, but when I want to use headless Chrome, then Selenium is not able to find the elements.
I added this options to my ChromeDriver:
ChromeOptions chromeOptions = new ChromeOptions();
chromeOptions.addArguments("--headless");
Console:
ChromeDriver was started successfully.
2020-08-27 22:41:46.625 INFO 20344 --- [ null to remote] o.o.selenium.remote.ProtocolHandshake : Detected dialect: W3C
Exception in thread "Thread-8" Exception in thread "Thread-10" org.openqa.selenium.TimeoutException: Expected condition failed: waiting for presence of element located by: By.cssSelector: [data-id='current-price'] (tried for 5 second(s) with 500 milliseconds interval)
at org.openqa.selenium.support.ui.WebDriverWait.timeoutException(WebDriverWait.java:95)
at org.openqa.selenium.support.ui.FluentWait.until(FluentWait.java:272)
at magharmi.asos.pricechecker.controller.PriceController$1.run(PriceController.java:52)
Caused by: org.openqa.selenium.NoSuchElementException: no such element: Unable to locate element: {"method":"css selector","selector":"[data-id='current-price']"}
(Session info: headless chrome=85.0.4183.83)
For documentation on this error, please visit: https://www.seleniumhq.org/exceptions/no_such_element.html
Build info: version: '3.141.59', revision: 'e82be7d358', time: '2018-11-14T08:17:03'
System info: host: 'DESKTOP-MMDJR4G', ip: '192.168.178.45', os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '13.0.1'
Driver info: org.openqa.selenium.chrome.ChromeDriver
While using headless mode you need to:
Maximize the browsing window
ChromeOptions options = new ChromeOptions();
options.addArguments("--window-size=1400,600");
Instead of presenceOfElementLocated() induce WebDriverWait for visibilityOfElementLocated() as follows:
WebElement element = new WebDriverWait(driver, 20).until(ExpectedConditions.visibilityOfElementLocated(By.cssSelector("[data-id='current-price']")));
Related
I am trying to run my automation on azure devops environment and phantomjs driver is getting timedout with below error message, can someone please help in resolving this problem
2019-10-30T16:13:27.8547904Z verifyXXXXActionPanel(com.xx.xxx.xxxxxxxx.tests.Dashboard.Testxxxxxxx) Time elapsed: 20.01 sec <<< FAILURE!
2019-10-30T16:13:27.8547948Z org.openqa.selenium.WebDriverException: Timed out waiting for driver server to start.
2019-10-30T16:13:27.8606707Z Build info: version: '3.141.59', revision: 'e82be7d358', time: '2018-11-14T08:17:03'
2019-10-30T16:13:27.8607855Z System info: host: '495c34b84843', ip: '172.17.42.5', os.name: 'Linux', os.arch: 'amd64', os.version: '4.15.0-1055-azure', java.version: '1.8.0_191'
2019-10-30T16:13:27.8607969Z Driver info: driver.version: PhantomJSDriver
2019-10-30T16:13:27.8608049Z at java.util.concurrent.FutureTask.get(FutureTask.java:205)
2019-10-30T16:13:27.8608497Z at com.google.common.util.concurrent.SimpleTimeLimiter.callWithTimeout(SimpleTimeLimiter.java:154)
2019-10-30T16:13:27.8608567Z at org.openqa.selenium.net.UrlChecker.waitUntilAvailable(UrlChecker.java:80)
2019-10-30T16:13:27.8608609Z at org.openqa.selenium.remote.service.DriverService.waitUntilAvailable(DriverService.java:177)
2019-10-30T16:13:27.8608650Z at org.openqa.selenium.remote.service.DriverService.start(DriverService.java:168)
2019-10-30T16:13:27.8608709Z at org.openqa.selenium.phantomjs.PhantomJSCommandExecutor.execute(PhantomJSCommandExecutor.java:78)
2019-10-30T16:13:27.8608751Z at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:601)
2019-10-30T16:13:27.8608792Z at org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:241)
2019-10-30T16:13:27.8608850Z at org.openqa.selenium.remote.RemoteWebDriver.(RemoteWebDriver.java:128)
2019-10-30T16:13:27.8608901Z at org.openqa.selenium.remote.RemoteWebDriver.(RemoteWebDriver.java:141)
2019-10-30T16:13:27.8608947Z at org.openqa.selenium.phantomjs.PhantomJSDriver.(PhantomJSDriver.java:115)
2019-10-30T16:13:27.8608987Z at org.openqa.selenium.phantomjs.PhantomJSDriver.(PhantomJSDriver.java:104)
2019-10-30T16:13:27.8609047Z at com.wm.bua.corpcreditcard.driverFactory.BrowserFactory.getWebDriver(BrowserFactory.java:195)
2019-10-30T16:13:27.8609088Z at com.wm.bua.corpcreditcard.driverFactory.BrowserFactory.getBrowser(BrowserFactory.java:61)
2019-10-30T16:13:27.8609129Z at com.wm.bua.corpcreditcard.tests.Dashboard.TestCorpCardManager.verifyManagerActionPanel(TestCorpCardManager.java:147)
below are the DesiredCapabilities which I tried using when trying to launch phantomjs driver
ClassLoader classLoader = new BrowserFactory().getClass().getClassLoader();
File phantomJS = new File(classLoader.getResource("drivers/phantomjs").getFile());
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability(PhantomJSDriverService.PHANTOMJS_EXECUTABLE_PATH_PROPERTY,phantomJS.getAbsolutePath());
String[] cli_args = new String[]{ "--ssl-protocol=tlsv1", "--ignore-ssl-errors=true", "--web-security=false" };
capabilities.setCapability(PhantomJSDriverService.PHANTOMJS_CLI_ARGS, "--webdriver-loglevel=ERROR");
capabilities.setCapability("takesScreenshot", false);
capabilities.setCapability(PhantomJSDriverService.PHANTOMJS_CLI_ARGS, cli_args);
capabilities.setCapability("locationContextEnabled", true);
capabilities.setCapability("applicationCacheEnabled", true);
capabilities.setCapability("browserConnectionEnabled", true);
capabilities.setCapability("localToRemoteUrlAccessEnabled", true);
WebDriver driver = new PhantomJSDriver(capabilities);
Phantomjs usage is deprecated. You are using selenium3
The above error occurs may be selenium version may be incompatible to phantomjs driver try a compatible version maybe it works
But I recommend you to go with Chrome headless
I think the existing stack post will help you
https://stackoverflow.com/a/36769777/12167800
Used Selenium Webdriver(V2.29), selenium-api version(3.4.0), Chrome
Version (62.0.3202.94) 64 bit and tried to run chrome browser in linux machine with the below code.
WebDriver driver;
String chromeBinaryPath = "/data/Package/CHROME_NEW";
String driverPath = "/data/Package/Selenium/WebDrivers/ChromeDrivers/chromedriver_linux32/chromedriver";
System.setProperty("webdriver.chrome.driver", driverPath);
System.setProperty("webdriver.chrome.verboseLogging","true");
System.setProperty("webdriver.chrome.logfile","/data/Package/log/chromedriver.log");
ChromeOptions optionsLinux64 = new ChromeOptions();
optionsLinux64.setBinary(chromeBinaryPath);
optionsLinux64.addArguments("--headless");
optionsLinux64.addArguments("--no-sandbox");
optionsLinux64.addArguments("--disable-gpu");
optionsLinux64.addArguments("--headless");
driver = new ChromeDriver(optionsLinux64);
When tried to create a chrome session, getting below exception:
unknown error: Chrome failed to start: exited abnormally (Driver info: chromedriver=2.29.461571 (8a88bbe0775e2a23afda0ceaf2ef7ee74e822cc5),platform=Linux 3.10.0-693.5.2.el7.x86_64 x86_64) (WARNING: The server did not provide any stacktrace information) Command duration or timeout: 60.10 seconds Build info: version: '3.4.0', revision: 'unknown', time: 'unknown' System info: host: 'el4014.bc', ip: '10.120.94.70', os.name: 'Linux', os.arch: 'amd64', os.version: '3.10.0-693.5.2.el7.x86_64', java.version: '1.8.0_151' Driver info: driver.version: ChromeDriver
Installed Chrome at /data/Package/CHROME_NEW folder using rpm file.
Message in chromedriver.log:
[0.204][DEBUG]: DevTools request: http://localhost:12111/json/version
LaunchProcess: failed to execvp:
/data/Package/CHROME_NEW/
[0.379][DEBUG]: DevTools request failed
Can anyone help me in resolving with the above issue.
This should be work:
ChromeOptions options = new ChromeOptions();
options.setHeadless(true);
Try adding window size
optionsLinux64.addArguments("window-size=1024x780");
I have the following code:
ChromeOptions chromeOptions = new ChromeOptions();
chromeOptions.addArguments("--headless");
webDriver = new ChromeDriver(chromeOptions);
It throws the exception:
Gtk-Message: Failed to load module "topmenu-gtk-module"
Created new window in existing browser session.
Exception in thread "main" org.openqa.selenium.WebDriverException:
Timed out waiting for driver server to start.
Build info: version: '3.4.0', revision: 'unknown', time: 'unknown'
System info: host: 'luis', ip: '127.0.1.1', os.name: 'Linux', os.arch: 'amd64', os.version: '4.4.0-87-generic', java.version: '1.8.0_112'
Driver info: driver.version: ChromeDriver
at org.openqa.selenium.remote.service.DriverService.waitUntilAvailable(DriverService.java:193)
at org.openqa.selenium.remote.service.DriverService.start(DriverService.java:181)
at org.openqa.selenium.remote.service.DriverCommandExecutor.execute(DriverCommandExecutor.java:78)
I'm new to this, am I missing something? Should be any other server running in my host?
First of all if you want to use chrome then you need to download it's binary from below URL :-
https://sites.google.com/a/chromium.org/chromedriver/
Now add System.setPropertybefore driver instance
System.setProperty("webdriver.chrome.driver","D:\\Workspace\\JmeterWebdriverProject\\src\\lib\\chromedriver.exe");
WebDriver driver = new ChromeDriver();
Nowif you want to use headless then use phantomjs. It is a stable build with you can use for your headleass jobs. donwload it from below link :-
http://phantomjs.org/download.html
Now add System.setPropertybefore driver instance
DesiredCapabilities caps = new DesiredCapabilities();
caps.setJavascriptEnabled(true); // not really needed: JS enabled by default
caps.setCapability(PhantomJSDriverService.PHANTOMJS_EXECUTABLE_PATH_PROPERTY, "C:/phantomjs.exe");
WebDriver driver = new PhantomJSDriver(caps);
refer the link below for more info :-
http://seleniumworks.blogspot.in/2013/03/headless-browser-testing-using.html
Hope it will help you :)
I am using Selenium Webdriver. I have searched many times and tried every answer in order to successfully testing a case. I am new to test automation.
Problem: There is an error when I use .sendKeys() and also click on some web element. I am really upset about this. I want to go forward with testing. Please help me solve this.
And also it displays an error stating InvalidValueError: initMap is not a function. Previously I have ran this codes successfully.
My setup is a follows:
Firefox 53.0
Eclipse Juno 32bit
Selenium Wevdriver 3.3.1
GeckoDriver 16.0
logger apache-log4j-1.2.17
This is the error:
1495778288530 geckodriver INFO Listening on 127.0.0.1:23817
1495778289152 mozprofile::profile INFO Using profile path
C:\Users\EXTROG~1\AppData\Local\Temp\rust_mozprofile.pTb73U1lR7sv
1495778289154 geckodriver::marionette INFO Starting browser C:\Program
Files\Mozilla Firefox\firefox.exe with args []
1495778289159 geckodriver::marionette INFO Connecting to Marionette on
localhost:50245 1495778293537 Marionette INFO Listening on port 50245
May 26, 2017 11:28:13 AM org.openqa.selenium.remote.ProtocolHandshake
createSession INFO: Detected dialect: W3C JavaScript error: , line 0:
uncaught exception: InvalidValueError: initMap is not a function INFO
[main] (SearchBarTest.java:20)- search bar is there Error : Expected
[object Undefined] undefined to be a string Build info: version:
'unknown', revision: '5234b32', time: '2017-03-10 09:00:17 -0800'
System info: host: 'EXTROGENE-PC', ip: '192.168.1.18', os.name:
'Windows 7', os.arch: 'x86', os.version: '6.1', java.version:
'1.8.0_121' Driver info: org.openqa.selenium.firefox.FirefoxDriver
Capabilities
[{moz:profile=C:\Users\EXTROG~1\AppData\Local\Temp\rust_mozprofile.pTb73U1lR7sv,
rotatable=false, timeouts={implicit=0, pageLoad=300000, script=30000},
pageLoadStrategy=normal, platform=ANY, specificationLevel=0,
moz:accessibilityChecks=false, acceptInsecureCerts=false,
browserVersion=53.0.3, platformVersion=6.1, moz:processID=1896,
browserName=firefox, platformName=windows_nt}] Session ID:
0d78f916-fa2e-4325-8baf-08b8e444d250
This is my code:
WebElement element=driver.findElement(By.xpath("//*[#id='serchkey']"));
driver.findElement(By.xpath("//*[#id='serchkey']")).sendKeys(new String("toy"));
Try this it may work:
WebElement element =driver.findElement(By.id("serchkey"));
javascriptSendKeys(element,"toy");
private void javascriptSendKeys(WebElement yourElement, String yourText){
JavascriptExecutor executor = (JavascriptExecutor)webDriver;
executor.executorScript("arguments[0].value='" + yourText + "';", yourElement);
}
Here is the Answer to your Question:
Great job done by specifying the Test Environment details as:
Selenium Webdriver 3.3.1
GeckoDriver 16.0
Now, if you have a look at the documentation of geckodriver v0.16.0 here, you will find a Heading as: "Note that geckodriver v0.16.0 is only compatible with Selenium 3.4 and greater."
So the solution to your Question is to upgrade your Selenium to 3.4.0 from here.
Let me know if this Answers your Question.
Seem to be getting this error waiting for popup window. As I am watching the script execute the js button executes and popup window does open but my test fails with the following error:
org.openqa.selenium.WebDriverException: disconnected: received Inspector.detached event
(Session info: chrome=56.0.2924.87)
(Driver info: chromedriver=2.28.455520 (cc17746adff54984afff480136733114c6b3704b),platform=Windows NT 6.1.7601 SP1 x86_64) (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 3.20 seconds
Build info: version: '2.53.1', revision: 'a36b8b1cd5757287168e54b817830adce9b0158d', time: '2016-06-30 19:26:09'
System info: host: '*******', ip: '*******', os.name: 'Windows 7', os.arch: 'amd64', os.version: '6.1', java.version: '1.8.0_91'
Driver info: org.openqa.selenium.chrome.ChromeDriver
Capabilities [{applicationCacheEnabled=false, rotatable=false, mobileEmulationEnabled=false, networkConnectionEnabled=false, chrome={chromedriverVersion=2.28.455520
This is about chrome issue(https://bugs.chromium.org/p/chromedriver/issues/detail?id=1194).
When you are running selenium program, you cannot press F12 to open dev tools manually, or it'll throw this exception sometimes. You can browse this chrome driver official page.
According to the issue list, it looks like fixed, but I still meet this bug in ChromeDriver 2.29.
Try updating your Chrome, I can see that your chromedriver version is 2.28 which is the most recent release and it should support Chrome v55-77, but updating Chrome might be a solution.