Selenium question
Posted by RedditUsrnamesRweird@reddit | learnprogramming | View on Reddit | 5 comments
I'm trying to setup my own basic automations using Selenium in Chrome.
I've been working with claude on this for my knoweldge gaps but we're hitting walls so I'm hoping the pro's may be able to help out or tell me what i'm trying to do is even possible (because AI won't tell you that you can't always be anything you want to be..)
At this point i'm just trying to run script 1 (open chrome, login) then run script 2 (click once). When script two starts , the chrome window closes, so nothing happens obviously.
Claude thinks webdriver.Chrome() connection via debuggerAddress is the solution but i keep getting the chrome window closing as my result.
I'm wondering if there's an industry standard for this and i'm trying to break the mold in a way that doesn't work. I've done some work with appium before and our senior devs setup everything so that our scripts logged in every single time regardless of how in-depth our test was.
All help is welcome thank you !
( This post is not in any way AI generated )
Only_SoccerHd@reddit
the real issue is that each script creates its own driver instance. you need to keep the first session alive and attach the second script to it using the debugger port. But honestly if you're just doing basic automations for login and clicking scrapfly has a scrape api that handles the browser session for you so you dont have to manage selenium at all. you just send your requests and it handles the rendering and session state. Might be easier than fighting with selenium session management for a beginner.
RedditUsrnamesRweird@reddit (OP)
I’ve never heard of scrap fly I’ll definitely have to take a look at it ty
Creative-Letter-4902@reddit
Your second script opens a new browser. Don't do that. One script, login then click. Done.
If you want two scripts, launch Chrome manually with debugger port first, then attach both to it.
Stuck? $20, 10 min call. Let me know.
NoConfidence4379@reddit
been down this road before and yeah, chrome closing between scripts is super annoying. the debugger address approach can work but you need to keep the first webdriver session alive while running script 2.
what i usually do is either combine both scripts into one longer script, or use chrome's remote debugging port to connect the second script to existing session. you start chrome with `--remote-debugging-port=9222` flag then connect your second script to that port instead of creating new webdriver instance.
the industry standard thing you mentioned is kinda true - most automation frameworks do fresh login each time because it's more reliable for testing, but for personal automation stuff keeping session alive makes total sense.
RedditUsrnamesRweird@reddit (OP)
Sounds good thank you for your help!