ABOUT ME

-

Today
-
Yesterday
-
Total
-
  • 셀레니움Selenium 주요 기능 모음, 주로 쓰는 메소드 모음
    직접 해보기/Python 2024. 6. 4. 23:23
    728x90
    반응형

     

    셀레니움 주요 클래스별 메소드


     

    ✔️ webdriver: 브라우저 제어 클래스.브라우저 인스턴스를 생성하고 제어함.

    • webdriver.Chrome(), webdriver.Firefox(), webdriver.Safari(), webdriver.Edge(): 브라우저 설정.
    • get(url): 특정 URL로 이동.
    • close(): 현재 브라우저 창 닫기.
    • quit(): 모든 브라우저 창 닫고 WebDriver 종료.
    • find_element(by, value): 단일 요소 찾기.
    • find_elements(by, value): 여러 요소 찾기.
    • save_screenshot(filename): 페이지 스크린샷 저장.

    ✔️ WebElement: 웹 페이지 요소와 상호작용할 때 사용하는 클래스.

    • click(): 요소 클릭.
    • send_keys(*value): 키보드 입력.
    • clear(): 요소 내용 지우기.
    • get_attribute(name): 요소 속성 값 반환.
    • is_displayed(): 요소 표시 여부 반환.
    • is_enabled(): 요소 활성화 여부 반환.
    • is_selected(): 요소 선택 여부 반환.

    ✔️ By: 요소를 찾기 위한 셀렉터 정의 클래스.

    • By.ID, By.NAME, By.CLASS_NAME, By.TAG_NAME, By.CSS_SELECTOR, By.XPATH
    • By.ID: ID를 기준으로 요소를 찾음.
    • By.XPATH: XPath를 기준으로 요소를 찾음.

    ✔️ Keys: 키보드 키를 입력할 때 사용하는 클래스.

    • Keys.RETURN, Keys.ENTER, Keys.TAB 등

    ✔️ WebDriverWait: 대기를 위한 조건을 정의하는 클래스.

    • until(method, message=''): 특정 조건 충족 시까지 기다림.
    • until_not(method, message=''): 특정 조건 충족되지 않을 시까지 기다림.

    ✔️ expected_conditions (EC) 요소가 어떤 상태인지 확인할때 사용하는 클래스.

    • presence_of_element_located(locator): 요소가 존재하는지 확인.
    • visibility_of_element_located(locator): 요소가 표시되는지 확인.
    • element_to_be_clickable(locator): 요소가 클릭 가능한 상태인지 확인.
    • text_to_be_present_in_element(locator, text): 특정 텍스트가 요소에 존재하는지 확인.

    ✔️ ActionChains: 복잡한 마우스와 키보드 액션을 수행하는 클래스.

    • click(on_element=None): 특정 요소 클릭.
    • double_click(on_element=None): 특정 요소 더블 클릭.
    • context_click(on_element=None): 특정 요소 오른쪽 클릭.
    • move_to_element(to_element): 마우스 특정 요소로 이동.
    • drag_and_drop(source, target): 소스 요소를 타겟 요소로 드래그 앤 드롭.
    • perform(): 체인된 모든 액션 실행.

     

     

     

    주요 클래스 클래스별 주요 메소드 메소드 기능 설명
    webdriver get(url) 특정 URL로 이동
    close() 현재 브라우저 창 닫기
    quit() 모든 브라우저 창 닫고 WebDriver 종료
    find_element(by, value) 단일 요소 찾기
    find_elements(by, value) 여러 요소 찾기
    get_cookies() 모든 쿠키 반환
    add_cookie(cookie_dict) 쿠키 추가
    delete_cookie(name) 특정 쿠키 삭제
    delete_all_cookies() 모든 쿠키 삭제
    execute_script(script, *args) JavaScript 코드 실행
    save_screenshot(filename) 페이지 스크린샷 저장
    WebElement click() 요소 클릭
    send_keys(*value) 키보드 입력
    clear() 요소 내용 지우기
    get_attribute(name) 요소 속성 값 반환
    is_displayed() 요소 표시 여부 반환
    is_enabled() 요소 활성화 여부 반환
    is_selected() 요소 선택 여부 반환
    By ID ID로 요소 찾기
    NAME 이름으로 요소 찾기
    CLASS_NAME 클래스 이름으로 요소 찾기
    TAG_NAME 태그 이름으로 요소 찾기
    CSS_SELECTOR CSS 셀렉터로 요소 찾기
    XPATH XPath로 요소 찾기
    Keys RETURN 리턴 키
    ENTER 엔터 키
    TAB 탭 키
    ActionChains click(on_element=None) 특정 요소 클릭
    double_click(on_element=None) 특정 요소 더블 클릭
    context_click(on_element=None) 특정 요소 오른쪽 클릭
    move_to_element(to_element) 마우스를 특정 요소로 이동
    drag_and_drop(source, target) 소스 요소를 타겟 요소로 드래그 앤 드롭
    perform() 체인된 모든 액션 실행
    WebDriverWait until(method, message='') 특정 조건 충족 시까지 기다림
    until_not(method, message='') 특정 조건 충족되지 않을 시까지 기다림
    expected_conditions presence_of_element_located(locator) 요소가 DOM에 존재하는지 확인
    visibility_of_element_located(locator) 요소가 표시되는지 확인
    element_to_be_clickable(locator) 요소가 클릭 가능한 상태인지 확인
    text_to_be_present_in_element(locator, text) 특정 텍스트가 요소에 존재하는지 확인

     

    728x90
    반응형