undetected-chromedriver/example/test_workflow.py

34 lines
949 B
Python
Raw Normal View History

2023-06-02 15:07:37 -06:00
import time
import logging
2023-06-02 16:06:25 -06:00
import os
2023-06-02 15:07:37 -06:00
logging.basicConfig(level=10)
from selenium.webdriver.remote.webdriver import By
2023-06-02 15:39:15 -06:00
import selenium.webdriver.support.expected_conditions as EC
2023-06-02 15:07:37 -06:00
from selenium.webdriver.support.wait import WebDriverWait
2023-06-02 16:06:25 -06:00
from pathlib import Path
2023-06-02 15:07:37 -06:00
import undetected_chromedriver as uc
2023-06-02 16:06:25 -06:00
# due to the randomneess of the chrome install path on the runner when running action, i have to find it manufally
tmp = Path('/tmp')
for item in tmp.glob('chrome*'):
if item.is_dir():
path_list = os.environ['PATH'].split(os.pathsep)
path_list.insert(0, str(item))
os.environ['PATH'] = os.pathsep.join(path_list)
2023-06-02 15:40:15 -06:00
def main():
2023-06-02 15:56:53 -06:00
driver = uc.Chrome(headless=True)
2023-06-02 15:39:15 -06:00
driver.get("https://nowsecure.nl")
WebDriverWait(driver, 15).until(EC.text_to_be_present_in_element(("css selector", "main h1"), "OH YEAH, you passed!"))
2023-06-02 15:07:37 -06:00
driver.quit()
if __name__ == "__main__":
2023-06-02 15:39:15 -06:00
2023-06-02 15:40:15 -06:00
main()
2023-06-02 15:39:15 -06:00