This is the two files that I have.
I need to run the principal file inside from test.
the principal file works perfectly.
And I cal the principal in the line 78 from test file.
the error appear is
import principal
ModuleNotFoundError: No module named 'principal'
Hope now is clear my situation
file name: test
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.common.exceptions import NoSuchElementException
def init_driver():
driver=webdriver.Firefox(executable_path="C:\\Users\\jpedr\\Desktop\\geckodriver-v0.26.0-win64\\geckodriver.exe")
driver.wait=WebDriverWait(driver, 5)
driver.get("https://www.")
return driver
def get_data(b,driver):
try:
driver.refresh()
import time
time.sleep(5)
driver.execute_script("window.scrollTo(0, document.body.scrollHeight);")
d1=driver.find_element_by_xpath("/html/body/div[2]/section[1]")
b=b+1
d2=driver.find_element_by_xpath("/html/body/div[2]/section[2]")
b=b+1
#etc....
except NoSuchElementException as e:
print("no more, total=",b)
get_data.b=b
driver=init_driver()
import time
time.sleep(5)
driver.refresh()
driver.execute_script("window.scrollTo(0, document.body.scrollHeight);")
import time
time.sleep(20)
i=0
try:
e1=driver.find_element_by_xpath("/html/body/div[2]/section[1]")
i=i+1
e2=driver.find_element_by_xpath("/html/body/div[2]/section[2]")
i=i+1
#etc...
except NoSuchElementException as e:
print("total", i)
get_data(0,driver)
print ("i=",i)
print ("get_data.b=",get_data.b)
while True:
print ("get_data.b=",get_data.b)
if i==get_data.b or get_data.b<i :
try:
import time
time.sleep(5)
print("replay funtion")
get_data(0,driver)
print("b", get_data.b)
except ValueError:
print("something happen")
break
if i!=get_data.b and get_data.b>i:
break
pass
if i!=get_data.b and get_data.b>i:
print("run another python file")
import principal
print("principal finished")
pass
file name: principal
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.common.exceptions import NoSuchElementException
from selenium.webdriver.common.action_chains import ActionChains
from selenium.webdriver.common.keys import Keys
def init_driver():
driver=webdriver.Firefox(executable_path="C:\\Users\\jpedr\\Desktop\\geckodriver-v0.26.0-win64\\geckodriver.exe")
driver.implicitly_wait(5) # seconds
driver.wait=WebDriverWait(driver, 15)
driver.get("https://www.")
return driver
def my_function(i,driver):
while i<b:
import time
time.sleep(15)
driver.execute_script("window.scrollTo(0, document.body.scrollHeight);")
element=driver.wait.until(EC.presence_of_element_located((By.XPATH,f[i])))
while True :
try:
if find_element_by_xpath(f[i]) is True:
element1=driver.find_element_by_xpath(f[i])
driver.find_element_by_xpath(f[i]).click()
except ValueError:
print("no more")
pass
try:
element = driver.find_element_by_xpath(f[i])
driver.execute_script("arguments[0].click();", element)
except NoSuchElementException as e:
print("no")
try:
myDynamicElement = driver.find_element_by_xpath("/html/body/div[2]/div/form/input")
driver.find_element_by_xpath("/html/body/div[2]/main/input").click()
except NoSuchElementException as e:
driver.wait.until(EC.presence_of_element_located((By.XPATH,"/html/body/div/form/input")))
import time
time.sleep(2)
driver.back()
i=i+1
a=0
i=0
b=0
bypass=0
driver=init_driver()
f1="/html/body/section[1]"
f2="/html/body/section[2]"
f=[f1,f2]
driver.wait.until(EC.presence_of_element_located((By.XPATH,"/html/body/section[1]")))
driver.execute_script("window.scrollTo(0, document.body.scrollHeight);")
try:
c1=driver.find_element_by_xpath("/html/body/section[1]")
a=a+1
except NoSuchElementException as e:
print("no")
import time
time.sleep(10)
if a>0:
driver.execute_script("window.scrollTo(0, document.body.scrollHeight);")
driver.find_element_by_xpath("/html/body/div[3]").click()
element=driver.wait.until(EC.presence_of_element_located((By.XPATH,"/html/body/section[1]")))
driver.find_element_by_xpath("/html/body").click()
try:
myDynamicElement = driver.find_element_by_xpath("/html/body/div[2]")
driver.execute_script("window.scrollTo(0, document.body.scrollHeight);")
import time
time.sleep(2)
driver.find_element_by_xpath("/html/body").click()
try:
myDynamicElement = driver.find_element_by_xpath("/html/body/div[2]
driver.find_element_by_xpath("/html/body/div[2]").click()
driver.wait.until(EC.presence_of_element_located((By.NAME,"username")))
driver.find_element_by_name("username")
import time
time.sleep(2)
driver.find_element_by_name("username").send_keys("")
driver.wait.until(EC.presence_of_element_located((By.NAME,"password")))
driver.find_element_by_name("password")
import time
time.sleep(2)
driver.find_element_by_name("password").send_keys("")
import time
time.sleep(2)
driver.wait.until(EC.presence_of_element_located((By.XPATH,"/html/body/div[2]")))
driver.find_element_by_xpath("/html/body")
driver.find_element_by_xpath("/html/body").click()
import time
time.sleep(2)
try:
driver.execute_script("window.scrollTo(0, document.body.scrollHeight);")
d1=driver.find_element_by_xpath("/html/body/div[2]/main/")
b=b+1
d2=driver.find_element_by_xpath("/html/body/div[2]")
b=b+1
except NoSuchElementException as e:
print("no more")
if b>0:
my_function(0,driver)