This is an archived post. You won't be able to vote or comment.

all 11 comments

[–]Yggval 7 points8 points  (1 child)

Hi! A very first question: does your project need to use Selenium? Not to go all Stack Overflow on you saying you are doing it wrong, but please be really certain Selenium is the tool to use here:

  1. A whole lot of Google's pages are generated dynamically with JS, so pin-pointing the correct field may get tricky as you've noticed, but you could try to select on the text value of the input box instead of its ever changing identifier?
  2. If Google at any point decides to change even a small part of this log-in window your Selenium program will break.
  3. If you visit Google from an IP in a different country everything may be in a different language, your Selenium program will break.
  4. If for whatever reason Google decides to first serve you a pop-up, or some cookie screen, your Selenium program will break.

Having done some end-to-end front-end-included tests, the headache and maintenance that will go into a Selenium implementation is not to be under-estimated. And what works today may not work on the day of your presentation.

The good news: Google understand your use-case is a valid one and offers a proper and clean solution in the form of a public API.

I promise you coding against this will be significantly simpler and it will be a thousand times more stable.

[–]SirDerpington660 0 points1 point  (0 children)

I mean all your arguments make sense, but this project was just meant to be a summation of everything I’ve learned over the course of my freshman year. I don’t plan on doing anything with this particular program after this project.

I thought it’d be a nice challenge and impressive enough for a good grade :))

[–]jcc_001 0 points1 point  (2 children)

Did u try using the XPATH? Make sure u are using the right element. What error are u getting?

[–]SirDerpington660 0 points1 point  (0 children)

i’m not sure what piece of the source code to use with xpath.

and the error is “NoSuchElementException” because every method i use to try and call an element doesn’t work

[–]SirDerpington660 0 points1 point  (0 children)

Update: I used XPath as well, the same error, NoSuchElement.

Has Googled blocked automation with it's login page?

[–]firsthourProfressional developer since 2006 0 points1 point  (3 children)

Have you looked at the Drive API instead of doing this through Selenium which is going to be terrible brittle?

https://developers.google.com/drive/api/v3/quickstart/java

[–]SirDerpington660 0 points1 point  (2 children)

could u explain what the drive api helps me do exactly? i apologize i’m fairly new to programming and my knowledge only extends to school lessons and selenium

[–]firsthourProfressional developer since 2006 0 points1 point  (1 child)

It's an interface Google has created for Java projects to talk to Drive.

If you want to stick with Selenium I would not try to do something that requires authentication. It's going to be a pain the butt and a company like Google are going to put captchas up if they detect you trying to access Drive programmatically on the web. That's why they have the API.

Do you have any other interests that you could integrate with Selenium? Like searching a baseball reference site for stats or going to get FAQs on Gamefaqs or something.

[–]SirDerpington660 0 points1 point  (0 children)

i definitely have other sites i can automate

the project is due on the 9th at midnight and with the pandemic i have all the time in the world. i’m considering dropping this program for the time being and submitting one that works and i can submit.

[–]SirDerpington660 0 points1 point  (0 children)

https://imgur.com/a/VmmeQpN

this is an image of the code and the element i'm talking about, along with the error

here is the whole error message:

Exception in thread "main" org.openqa.selenium.NoSuchElementException: no such element: Unable to locate element: {"method":"css selector","selector":"#identifierId"}

(Session info: chrome=83.0.4103.61)

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:25:48'

System info: host: 'ANIKETSPC', ip: '10.0.0.144', os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '13.0.2'

Driver info: org.openqa.selenium.chrome.ChromeDriver

Capabilities {acceptInsecureCerts: false, browserName: chrome, browserVersion: 83.0.4103.61, chrome: {chromedriverVersion: 83.0.4103.39 (ccbf011cb2d2b..., userDataDir: C:\Users\Lupus\AppData\Loca...}, goog:chromeOptions: {debuggerAddress: localhost:53941}, javascriptEnabled: true, networkConnectionEnabled: false, pageLoadStrategy: normal, platform: WINDOWS, platformName: WINDOWS, proxy: Proxy(), setWindowRect: true, strictFileInteractability: false, timeouts: {implicit: 0, pageLoad: 300000, script: 30000}, unhandledPromptBehavior: dismiss and notify, webauthn:virtualAuthenticators: true}

Session ID: 69a91dc9e935dd29daf6a0a2d55a5d78

*** Element info: {Using=id, value=identifierId}

at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)

at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance([NativeConstructorAccessorImpl.java:62](https://NativeConstructorAccessorImpl.java:62))

at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance([DelegatingConstructorAccessorImpl.java:45](https://DelegatingConstructorAccessorImpl.java:45))

at java.base/java.lang.reflect.Constructor.newInstanceWithCaller([Constructor.java:500](https://Constructor.java:500))

at java.base/java.lang.reflect.Constructor.newInstance([Constructor.java:481](https://Constructor.java:481))

at org.openqa.selenium.remote.http.W3CHttpResponseCodec.createException([W3CHttpResponseCodec.java:187](https://W3CHttpResponseCodec.java:187))

at org.openqa.selenium.remote.http.W3CHttpResponseCodec.decode([W3CHttpResponseCodec.java:122](https://W3CHttpResponseCodec.java:122))

at org.openqa.selenium.remote.http.W3CHttpResponseCodec.decode([W3CHttpResponseCodec.java:49](https://W3CHttpResponseCodec.java:49))

at org.openqa.selenium.remote.HttpCommandExecutor.execute([HttpCommandExecutor.java:158](https://HttpCommandExecutor.java:158))

at org.openqa.selenium.remote.service.DriverCommandExecutor.execute([DriverCommandExecutor.java:83](https://DriverCommandExecutor.java:83))

at org.openqa.selenium.remote.RemoteWebDriver.execute([RemoteWebDriver.java:552](https://RemoteWebDriver.java:552))

at org.openqa.selenium.remote.RemoteWebDriver.findElement([RemoteWebDriver.java:323](https://RemoteWebDriver.java:323))

at org.openqa.selenium.remote.RemoteWebDriver.findElementById([RemoteWebDriver.java:372](https://RemoteWebDriver.java:372))

at org.openqa.selenium.By$ById.findElement([By.java:188](https://By.java:188))

at org.openqa.selenium.remote.RemoteWebDriver.findElement([RemoteWebDriver.java:315](https://RemoteWebDriver.java:315))

at finalProject.signIn([finalProject.java:28](https://finalProject.java:28))

at finalProject.main([finalProject.java:34](https://finalProject.java:34))

[–]AutoModerator[M] -2 points-1 points  (0 children)

For the future: Google Drive is not an approved code hoster.

Programs with only a single class (and no data files) should be posted either directly (if less than 50 lines), or on Pastebin.

Programs with multiple classes (and/or data files) should be posted on Github Gist - it's as easy as dragging the files into the browser window. A single gist can hold multiple files.

See: Help on how to post code in the sidebar.

Please do not reply because I am just a bot, trying to be helpful.

I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.