Variables in 2 files and selenium

python

#1

Hello everybody, i’ve starter to program with python and now I don’t know how link correctly this 2 files
I’ve created the main.py and the login.py, then i tried to link the 2 files together
I’m using selenium and the program works, but it open 2 chrome windows(When I want to open just one)
then, the second one keep go ahead and works perfectly but when it stop to do what i told to do suddently this error come:

Traceback (most recent call last):
  File "C:/Users/alebu/PycharmProjects/selenium/Main.py", line 9, in <module>
    Login.login()
  File "C:\Users\alebu\PycharmProjects\selenium\Login.py", line 6, in login
    Main.browser.find_element_by_link_text('Log in').click()
  File "C:\Users\alebu\PycharmProjects\selenium\venv\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 419, in find_element_by_link_text
    return self.find_element(by=By.LINK_TEXT, value=link_text)
  File "C:\Users\alebu\PycharmProjects\selenium\venv\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 955, in find_element
    'value': value})['value']
  File "C:\Users\alebu\PycharmProjects\selenium\venv\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 312, in execute
    self.error_handler.check_response(response)
  File "C:\Users\alebu\PycharmProjects\selenium\venv\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 242, in check_response
    raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: {"method":"link text","selector":"Log in"}
  (Session info: chrome=64.0.3282.167)
  (Driver info: chromedriver=2.35.528161 (5b82f2d2aae0ca24b877009200ced9065a772e73),platform=Windows NT 10.0.16299 x86_64)


Process finished with exit code 1

probably I’ve done something wrong with the variables
the main.py

from selenium import webdriver
import Login

driver_location = "C:\webDrivers\chromedriver.exe"
options = webdriver.ChromeOptions()
options.add_argument('--lang=en')
browser = webdriver.Chrome(executable_path=driver_location, chrome_options=options)
Login.login()





the login.py

def login():
    import Main
    from time import sleep
    Main.browser.get('https://www.instagram.com')

    Main.browser.find_element_by_link_text('Log in').click()

    Main.browser.find_element_by_name('username').send_keys('*******')
    Main.browser.find_element_by_name('password').send_keys(********')

    Main.browser.find_element_by_xpath('//form/span/button[text()="Log in"]').click()
    sleep(3)
    Main.browser.find_element_by_link_text('Not Now').click()
    sleep(2)
    print("Logged In")

the weird thing is , before the program was in one uniqe file and it worked perfectly

Thankyou :slight_smile:


#2

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.