0

I have two python scripts. In one script, "start_browser.py", I open the browser on the page I need:

from selenium import webdriver
drv = webdriver.Chrome(options=options)
drv.get('http//some_site')

In the second script, I have the code to fill in the web form "web_form.py:

drv.find_element_by_xpath('//some_xpath"]').value  = 'some_text'

How can I use the drv defined in the first script in the second script to continue working in a browser open with the first script "start_browser.py"? When I try to execute this code in the second script, I get an error:

NameError: name 'drv' is not defined

UPD: I will change my question. In other words, I need so that I can launch the browser by pressing one button (for example, in tkinter), and then after loading the browser, run another script by pressing another button and the window created on tkinter and do further actions in the browser that is already open with driver defined in first script

giovanii111
  • 47
  • 1
  • 8

1 Answers1

0

I cannot comment but try this: In web_form.py, at the top try to import start_browser. This might clear up the name error.

Cyber Pig
  • 1
  • 2
  • Thanks for your reply. I tried to do as you said, but this led to the fact that when the second script "web_form.py" was launched, another browser was opened on and moved to the same address as when the "start_browser.py" script was run – giovanii111 Jun 20 '20 at 20:02
  • In the second script (web_form.py) did you import selenium as well? – Cyber Pig Jun 20 '20 at 20:47
  • In the second file, I do the import like this: ```import browser_start_on_site``` and ```from selenium import webdriver``` But when you run the second web_form.py script, another browser still opens – giovanii111 Jun 21 '20 at 12:10