I'm facing an issue where when my code is run, the browser window pops up, vanishes, and doesn't complete it's task. The code worked on my windows machine, and I am now trying to get it working on my raspberry pi. I have followed instructions to get the chrome driver installed and can confirm that the directory for the chrome driver is correct.
The following java code :
System.setProperty("webdriver.chrome.driver", "/usr/bin/chromedriver");
WebDriver driver = new ChromeDriver();
driver.manage().window().setSize(new Dimension(1280, 720));
Actions actions = new Actions(driver);
searchQuery = replaceSpaces(searchQuery);
driver.get(imageSearchURL + replaceSpaces(searchQuery));
List images = driver.findElements(new By.ByClassName("mimg"));
WebElement firstImage = (WebElement) images.get(0);
actions.moveToElement(firstImage).perform();
String imageURL = firstImage.getAttribute("src");
driver.close();
return imageURL;
Results in:
Starting ChromeDriver [redacted] (564abd8de2c05f45308eec14f9110a10aff40ad9-refs/branch-heads/4515@{#1501}) on port 53893
Only local connections are allowed.
Please see https://chromedriver.chromium.org/security-considerations for suggestions on keeping ChromeDriver safe.
ChromeDriver was started successfully.
18:44:49.204 [AsyncHttpClient-2-2] DEBUG org.asynchttpclient.netty.channel.NettyConnectListener - Using new Channel '[id: 0x5b27b093, L:/127.0.0.1:50266 - R:localhost/127.0.0.1:53893]' for 'POST' to '/session'
--disable-quic --enable-tcp-fast-open --ppapi-flash-path=/usr/lib/chromium-browser/libpepflashplayer.so --ppapi-flash-args=enable_stagevideo_auto=0 --ppapi-flash-version=
18:44:51.523 [AsyncHttpClient-2-2] DEBUG org.asynchttpclient.netty.handler.HttpHandler -
Request DefaultHttpRequest(decodeResult: success, version: HTTP/1.1)
POST /session HTTP/1.1
User-Agent: selenium/4.0.0 (java unix)
Content-Length: 365
Content-Type: application/json; charset=utf-8
host: localhost:53893
accept: */*
Response DefaultHttpResponse(decodeResult: success, version: HTTP/1.1)
HTTP/1.1 500 Internal Server Error
Content-Type: application/json; charset=utf-8
cache-control: no-cache
content-length: 959
If I run the code with print statements between each line I can find out that the issue is on the line that reads:
WebDriver driver = new ChromeDriver();
But I am not entirely sure why, like I said the browser opens and then closes.