Variables in 2 files and selenium

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 and the, 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/", line 9, in <module>
  File "C:\Users\alebu\PycharmProjects\selenium\", 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\", 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\", line 955, in find_element
    'value': value})['value']
  File "C:\Users\alebu\PycharmProjects\selenium\venv\lib\site-packages\selenium\webdriver\remote\", line 312, in execute
  File "C:\Users\alebu\PycharmProjects\selenium\venv\lib\site-packages\selenium\webdriver\remote\", 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

from selenium import webdriver
import Login

driver_location = "C:\webDrivers\chromedriver.exe"
options = webdriver.ChromeOptions()
browser = webdriver.Chrome(executable_path=driver_location, chrome_options=options)


def login():
    import Main
    from time import sleep

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


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

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

Thankyou :slight_smile:

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