본문 바로가기
VBA/엑사남_심화방

[심화방] VBA_심화_100제 #12 [ 셀레니움 자동화테스트]

by 일등미노왕국 2023. 3. 16.

 

셀레니움 사이트 자동화 테스트이다.

사이트 주소는 다음과 같다.

https://www.tutorialspoint.com/selenium/selenium_automation_practice.htm

 

Selenium - Automation Practice Form

Selenium Automation Practice Form -

www.tutorialspoint.com

드롭박스를 선택하는 방법은 아래와 같은데...AsSelect의 매소드로 인덱스, 값과 옵션등 여러가지가 더 있으니 연구해보길 바란다.

Sel.FindElementByCss("select[name='continents']").AsSelect.SelectByText "Asia"

더보기
Sub Sel_Exp()

    Dim strUrl$

    strUrl = "https://www.tutorialspoint.com/selenium/selenium_automation_practice.htm"

   ' Sel.AddArgument "--headless"                                        '= 헤드리스모드
    Sel.Start "chrome"                                                  '= 크롬으로 진행
    Sel.Get strUrl                                                      '= Url 이동
    
    Sel.FindElementByCss("input[name='firstname']").SendKeys "Haja"             '= First name
    Sel.FindElementByCss("input[name='lastname']").SendKeys "ExaNam"            '= Last name
    
    Sel.FindElementByCss("input[value='Male']").Click                           '= Sex
    
    Sel.FindElementByCss("input[value='5']").Click                              '= Years of Experience
   
    Sel.FindElementByCss("tbody > tr:nth-child(5) > td:nth-child(2) > input[type=text]").SendKeys Format(Now, "yyyy-mm-dd")
                                                                                '= Date
    Sel.FindElementByCss("input[value='Automation Tester']").Click              '= Profession
    
    Sel.FindElementByCss("input[type='file']").ClickDouble                      '= Profile Picture
    
    Application.Wait Now + TimeValue("0:00:02")                                 '= 2초 대기
    SendKeys "C:\Users\DRP_MAIN\Pictures\방탄소년단.jpg" & "{enter}"            '= 파일경로
    
    Application.Wait Now + TimeValue("0:00:02")                                 '= 2초 대기
    SendKeys "C:\Users\DRP_MAIN\Pictures\방탄소년단.jpg" & "{enter}"            '= 파일경로
    
    Sel.FindElementByCss("input[value='Selenium Webdriver']").Click             '= Flavours of Selenium
    
    Sel.FindElementByCss("select[name='continents']").AsSelect.SelectByText "Asia" '= Continents
    
    Sel.FindElementByCss("select[name='selenium_commands']").AsSelect.SelectByText "WebElement Commands"
                                                                                '= Selenium Commands
    Sel.FindElementByCss("button[name='submit']").Submit                        '= Button click
    
   ' Sel.SwitchToAlert.Accept                                                   '= 경고창 확인
    Sel.SwitchToAlert.Dismiss                                                   '= 경고창 취소
    
    MsgBox "완료하였습니다."
    
End Sub

심화방12xlsm.xlsm
0.02MB

댓글