Welcome to 16892 Developer Community-Open, Learning,Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I am following the flaskr tutorial so my code is similar to (https://flask.palletsprojects.com/en/1.1.x/tutorial/). I am also following the Selenium PageObjects tutorial (https://selenium-python.readthedocs.io/page-objects.html).

flask_tutorial
├── flaskr
│?? ├── auth.py
│?? ├── company_database.py
│?? ├── __init__.py
│?? ├── PageObjects
│?? │?? ├── element.py
│?? │?? ├── geckodriver.log
│?? │?? ├── locators.py
│?? │?? ├── main.py
│?? │?? ├── page.py
│?? │?? └── README.ME
│?? ├── schema.sql
│?? ├── static
│?? │?? └── style.css
│?? └── templates
│??     ├── auth
│??     ├── base.html
│??     └── index.html
├── instance
│?? └── flask.sqlite
└── setup.py

At the beginning I am importing my PageObject main.py file; PythonOrgSearch class in flaskr/auth.py.

from flask import (
    Blueprint, flash, g, redirect, render_template, request, session, url_for
)

from .PageObjects.main import PythonOrgSearch

The PythonOrgSearch class imports page module.

import unittest
from selenium import webdriver
import sys

import page

class PythonOrgSearch(unittest.TestCase):

Why can't it import the page.py module?

Error

Traceback (most recent call last):
  File "/home/nbosio1001/anaconda3/lib/python3.7/site-packages/flask/cli.py", line 83, in find_best_app
    app = call_factory(script_info, app_factory)
  File "/home/nbosio1001/anaconda3/lib/python3.7/site-packages/flask/cli.py", line 119, in call_factory
    return app_factory()
  File "/home/nbosio1001/Documents/python/Fundamental_Analysis/app/flask_tutorial/flaskr/__init__.py", line 41, in create_app
    from . import auth
  File "/home/nbosio1001/Documents/python/Fundamental_Analysis/app/flask_tutorial/flaskr/auth.py", line 7, in <module>
    from .PageObjects.main import PythonOrgSearch
  File "/home/nbosio1001/Documents/python/Fundamental_Analysis/app/flask_tutorial/flaskr/PageObjects/main.py", line 5, in <module>
    import page
ModuleNotFoundError: No module named 'page'

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
3.7k views
Welcome To Ask or Share your Answers For Others

1 Answer

You may need an __init__.py file in the PageObjects directory.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to 16892 Developer Community-Open, Learning and Share
...