[vb.net] Selenium WebDriver 파일(이미지, 동영상) 업로드 및 내용 붙여넣기 샘플 > vb.net

본문 바로가기

vb.net

[Chrome] [vb.net] Selenium WebDriver 파일(이미지, 동영상) 업로드 및 내용 붙여넣기 샘플

회원사진
하나를하더라도최선을
2020-05-23 22:21 4,788 0

본문



'// 본문에 Ctrl + v 하기
 
    _IE.SwitchTo().ParentFrame() : _IE.SwitchTo().ParentFrame() : _IE.SwitchTo().ParentFrame()
    _IE.SwitchTo().Frame("mainFrame")
    _IE.SwitchTo().Frame("se2_iframe")
    activeElement = _IE.FindElement(By.XPath("/html/body/p"))
    Dim act As Actions = New Actions(_IE)
    act.MoveToElement(activeElement)
    act.KeyDown(Keys.Shift).SendKeys(Keys.End).KeyUp(Keys.Shift) '// 문서의 끝으로 이동
    act.SendKeys(Keys.Enter) '// 한줄 삽입
    act.KeyDown(Keys.Control).SendKeys("v").KeyUp(Keys.Control) '// 붙여넣기
    act.Perform() '// 작업 적용
 
 
'// 네이버 SmartEditor 2.0 이미지 업로드
 
    Dim IMAGE As String = T.Split(">"c)(1).Split("<")(0)
 
    _IE.SwitchTo().Window(_IE.WindowHandles.First)
    _IE.SwitchTo().ParentFrame() : _IE.SwitchTo().ParentFrame() : _IE.SwitchTo().ParentFrame()
    _IE.SwitchTo().Frame("mainFrame")
 
    LOG("이미지 업로드 버튼을 클릭합니다.")
    ByXPathClick("//*[@id=""se2_tool""]/div[1]/ul[1]/li[1]/button")
 
    Sleep(500) : Application.DoEvents()
    Sleep(500) : Application.DoEvents()
 
 
    _IE.SwitchTo().Window(_IE.WindowHandles.Last)
 
    LOG("팝업을 제거합니다.")
    ByXPathClick("/html/body/div[2]/div/button")    '// 팝업 제거
 
    LOG("업로드 버튼을 클릭합니다.")
    ByXPathClick("/html/body/div[3]/header/div[1]/label")   '// 내 PC 클릭
    LOG("파일 업로드 창을 찿습니다.")
    Dim hWnd As IntPtr
    Do
        If Not _STATUS Then GoTo WorkStop
        Application.DoEvents()
        hWnd = FindWindowEx(00, vbNullString, "열기")
    Loop Until hWnd <> IntPtr.Zero
 
    LOG("파일 대화상자를 찿습니다.")
    LOG("파일을 첨부합니다.")
 
    MakeTopMost(hWnd)  '// 파일 선택창을 맨 위로
    SetForegroundWindow(hWnd)
    Delay(1500)
    SetForegroundWindow(hWnd)
 
    SendKeys.SendWait(String.Format("{0}{1}", IMAGE, "{Enter}"))    '// 특수문자 사용금지
    'CreateObject("WScript.Shell").SendKeys(IMAGE, False)    '// 한글 + 특수문자 사용금지
 
    Sleep(500) : Application.DoEvents()
    Sleep(500) : Application.DoEvents()
    Sleep(500) : Application.DoEvents()
    Sleep(500) : Application.DoEvents()
 
    LOG("올리기 버튼을 클릭합니다.")
    ByXPathClick("/html/body/div[3]/header/div[2]/button")  '// 올리기 클릭
 
    Sleep(500) : Application.DoEvents()
    Sleep(500) : Application.DoEvents()
 
    LOG("원래 창으로 복귀합니다.")
    _IE.SwitchTo().Window(_IE.WindowHandles.First)
    _IE.SwitchTo().ParentFrame() : _IE.SwitchTo().ParentFrame() : _IE.SwitchTo().ParentFrame()
    _IE.SwitchTo().Frame("mainFrame")
    _IE.SwitchTo().Frame("se2_iframe")
 
    LOG("입력창을 찿습니다.")
    activeElement = _IE.FindElement(By.XPath("/html/body/p"))
 
    Application.DoEvents()
 
 
 
'// 네이버 SmartEditor 2.0 동영상 업로드
 
    Dim MOVIE As String = T.Split(">"c)(1).Split("<")(0)
 
    _IE.SwitchTo().Window(_IE.WindowHandles.First)
    _IE.SwitchTo().ParentFrame() : _IE.SwitchTo().ParentFrame() : _IE.SwitchTo().ParentFrame()
    _IE.SwitchTo().Frame("mainFrame")
 
    LOG("동영상 업로드 버튼을 클릭합니다.")
    ByXPathClick("//*[@id=""se2_tool""]/div[1]/ul[1]/li[2]/button")
 
    Sleep(500) : Application.DoEvents()
    Sleep(500) : Application.DoEvents()
 
    LOG("업로드 창으로 이동합니다.")
    _IE.SwitchTo().Window(_IE.WindowHandles.Last)
    _IE.SwitchTo().ParentFrame() : _IE.SwitchTo().ParentFrame() : _IE.SwitchTo().ParentFrame()
 
    LOG("파일 선택창을 오픈합니다.")
    activeElement = ByXPathElement("//*[@id=""_video""]/div[2]/div/div[1]/div[1]/span/span")
 
    Dim act As Actions = New Actions(_IE)
    act.MoveToElement(activeElement)
    act.Click()
    act.Perform()
 
    LOG("파일 업로드 창을 찿습니다.")
    Dim hWnd As IntPtr
    Do
        If Not _STATUS Then GoTo WorkStop
        Application.DoEvents()
        hWnd = FindWindowEx(00, vbNullString, "열기")
    Loop Until hWnd <> IntPtr.Zero
 
    LOG("파일 대화상자를 찿습니다.")
    LOG("파일을 첨부합니다.")
 
    MakeTopMost(hWnd)  '// 파일 선택창을 맨 위로
    SetForegroundWindow(hWnd)
    Delay(1500)
    SetForegroundWindow(hWnd)
 
    SendKeys.SendWait(String.Format("{0}{1}", MOVIE, "{Enter}"))    '// 특수문자 사용금지
    'CreateObject("WScript.Shell").SendKeys(IMAGE, False)    '// 한글 + 특수문자 사용금지
 
    Sleep(500) : Application.DoEvents()
    Sleep(500) : Application.DoEvents()
    Sleep(500) : Application.DoEvents()
    Sleep(500) : Application.DoEvents()
 
    _IE.Manage.Timeouts.SetPageLoadTimeout(TimeSpan.FromMilliseconds(10000))
 
    LOG("올리기 버튼을 클릭합니다.")
    ByXPathClick("//*[@id=""_video""]/div[2]/div/div[5]/div[3]/a")  '// 올리기 클릭
 
    Sleep(500) : Application.DoEvents()
    Sleep(500) : Application.DoEvents()
 
    LOG("매인 창으로 복귀합니다.")
    _IE.SwitchTo().Window(_IE.WindowHandles.First)
    _IE.SwitchTo().ParentFrame() : _IE.SwitchTo().ParentFrame() : _IE.SwitchTo().ParentFrame()
    _IE.SwitchTo().Frame("mainFrame")
    _IE.SwitchTo().Frame("se2_iframe")
 
    LOG("입력창을 찿습니다.")
    activeElement = _IE.FindElement(By.XPath("/html/body/p"))
 
    Application.DoEvents()

댓글목록0

등록된 댓글이 없습니다.
게시판 전체검색