//MainFile.Py
import time
from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.common.by import By
driver.maximize_window()
driver.get("https://onesys.com/")
time.sleep(5)
username = driver.find_element(By.ID, "okta-signin-username")
password = driver.find_element(By.ID, "okta-signin-password")
username.send_keys("username")
password.send_keys("password")
driver.find_element(By.ID, "okta-signin-submit").click()
driver.find_element(By.XPATH, '').click()
import Report
exec("Report.py")
//Report.py
from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
s = Service(r'C:\Users\taranums\Downloads\chromedriver_win32\chromedriver')
driver = webdriver.Chrome(service=s)
driver.maximize_window()
driver.get("https://onesys.com/")
driver.find_element(By.XPATH, '').click()
driver.find_element(By.XPATH, '').click()
上面的代碼在第一個檔案中作業正常,但第二個檔案只有新的 chrome 瀏覽器在沒有網站的情況下打開,我希望第一個檔案執行,而不是在同一個瀏覽器上執行第二個檔案,以便將 Iam new 添加到 python selenium,任何人都可以請幫助,在此先感謝。
uj5u.com熱心網友回復:
您將事物組織成函式:
主檔案.py:
import time
from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.common.by import By
import Report
def finder(driver):
driver.maximize_window()
driver.get("https://onesys.com/")
time.sleep(5)
username = driver.find_element(By.ID, "okta-signin-username")
password = driver.find_element(By.ID, "okta-signin-password")
username.send_keys("username")
password.send_keys("password")
driver.find_element(By.ID, "okta-signin-submit").click()
driver.find_element(By.XPATH, '').click()
def main():
s = Service(r'C:\Users\taranums\Downloads\chromedriver_win32\chromedriver')
driver = webdriver.Chrome(service=s)
finder(driver)
Report.finder(driver)
if __name__ == "__main__":
main()
報告.py:
from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
def finder(driver):
driver.maximize_window()
driver.get("https://onesys.com/")
driver.find_element(By.XPATH, '').click()
driver.find_element(By.XPATH, '').click()
def main():
s = Service(r'C:\Users\taranums\Downloads\chromedriver_win32\chromedriver')
driver = webdriver.Chrome(service=s)
finder(driver)
if __name__ == "__main__":
main()
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/416038.html
標籤:
上一篇:如何打開一個新視窗并關閉上一個視窗?使用python和selenium
下一篇:SyntaxError:使用Selenium和ChromeDriver在XPath中掃描三引號字串文字時出現EOF?
