NoSuchElementException when running script
Closed this issue · 11 comments
Thanks for the amazing script! I had to make a couple of tweaks to get it to work so far:
-
Dependency on
sendgrid
isn't mentioned (sudo pip3 install sendgrid) -
The google chrome options didn't work ("This version of ChromeDriver only supports Chrome version 81"), but I replaced
chrome_options = Options()
chrome_options.binary_location = os.environ.get('GOOGLE_CHROME_SHIM')
driver = webdriver.Chrome(chrome_options=chrome_options)
with (after installing webdriver_manager)
from webdriver_manager.chrome import ChromeDriverManager
driver = webdriver.Chrome(ChromeDriverManager().install())
and that worked! This was as suggested here: https://stackoverflow.com/questions/60296873/sessionnotcreatedexception-message-session-not-created-this-version-of-chrome
Anyway, now the script seems to work, opening up Chrome and so on, but then it throws the following error:
Message: 'An error occurred while trying to access stackoverflow.com!'
Arguments: (NoSuchElementException('no such element: Unable to locate element: {"method":"css selector","selector":".mini-avatar"}\n (Session info: chrome=83.0.4103.61)', None, None),)
Any idea how to fix that?
Thanks for the updates. I didn't test the script lately, and it must have become obsolete with the latest Chrome versions. I'll make the suggested change in the code in the following days, or please feel free to raise a Pull Request for that.
With regards to the error, the StackOverflow has changed their UI, and the old CSS identifiers don't match anymore, that's why the error.
To fix it, try replacing
elem = driver.find_element_by_class_name("mini-avatar")
with
elem = driver.find_element_by_class_name("grid--cell ws-nowrap fs-body3")
Hope it works, I didn't test it. Let me know the outcome.
Thanks for the quick response. I would be happy to put in a pull request for the changes I've found -- not right away (need to start work for today :) ) but I can do it in the next week (or let you know if I can't)
What you said didn't quite work, but I did some quick debugging and investigation and it seems to be fixed by replacing the spaces with periods:
elem = driver.find_element_by_class_name("grid--cell.ws-nowrap.fs-body3")
(Another missing dependency from the step-by-step guide on medium:
pip install requests_oauthlib
)
I've fixed this and a few other issues in the following fork that I'm maintaining: https://github.com/cdstanford/stackoverflow-fanatic-badge
and updated the README with some additional instructions. I can make a PR when this is done.
Currently I'm trying to resolve the following issue that came up when getting an access token from StackExchange: #11
@alexsomai Maybe you should also update it in the gist so it is updated in the Medium article
I forked your gist, is it ok?
https://gist.github.com/cyb3rko/a9308ce77e3c2684e49a9050ae5340d0
Right, I forgot about the gist 🤦. Thanks for reminding me, @cyb3rko. I'll make sure to update it these days.
Yep, your fork is the correct version.
Perfect! And you mentioned it in the article below the gist.
Done. I've updated the Medium article, as well.
And I think the api gist could also get an update, right?
Yes, it is quite outdated 😞. I'll make time these days to look into it.