셀레니움 클릭 테스트를 하려고 1 to 50 사이트를 이용하여 클릭 테스트를 하려고 했다.

python code

from selenium import webdriver

driver = webdriver.Chrome('chromedriver')
driver.get('http://zzzscore.com/1to50')
driver.implicitly_wait(300)

#전역변수
#현재 찾아야될 숫자
num = 1

def clickBtn():
    global num
    btns = driver.find_elements_by_xpath('//*[@id="grid"]/div[*]')

    for btn in btns:
        print(btn.text, end='\t')
        if btn.text == str(num):
            btn.click()
            print(True)
            num += 1
            return

while num<=50:
    clickBtn()

이렇게 하고 런을 돌리니까 selenium PS C:\python> [14948:6844:0829/235610.230:ERROR:device_event_log_impl.cc(214)] [23:56:10.230] USB: usb_device_handle_win.cc:1048 Failed to read descriptor from node connection: 시스템에 부착된 장치가 작동하지 않습니다. (0x1F)


뭐 이런 생판 처음 보는 에러가 나타났다. 구글링을 해본 결과 코드에

options = webdriver.ChromeOptions()
options.add_experimental_option("excludeSwitches", ["enable-logging"])
browser = webdriver.Chrome(options=options)
browser.get('http://zzzscore.com/1to50/')
browser.implicitly_wait(time_to_wait=5)

이것만 추가해주면 된다고 한다.
그래서 추가해주었다.

python code2

from selenium import webdriver

#추가한 코드
options = webdriver.ChromeOptions()
options.add_experimental_option("excludeSwitches", ["enable-logging"])
browser = webdriver.Chrome(options=options)
browser.get('http://zzzscore.com/1to50/')
browser.implicitly_wait(time_to_wait=5)
#전역변수
#현재 찾아야될 숫자
num = 1

def clickBtn():
    global num
    btns = browser.find_elements_by_xpath('//*[@id="grid"]/div[*]')

    for btn in btns:
        print(btn.text, end='\t')
        if btn.text == str(num):
            btn.click()
            print(True)
            num += 1
            return

while num<=50:
    clickBtn()

그리고 런을 해보니까
selenium

selenium.common.exceptions.ElementClickInterceptedException: Message: element click intercepted: Element <div style="opacity: 1;">...</div> is not clickable at 
point (435, 650). Other element would receive the click: <iframe id="aswift_4" name="" sandbox="allow-forms allow-popups allow-popups-to-escape-sandbox allow-same-origin allow-scripts allow-top-navigation-by-user-activation" width="1005" height="124" frameborder="0" src="https://googleads.g.doubleclick.net/pagead/html/r20210823/r20110914/zrt_lookup.html?fsb=1#RS-1-&amp;adk=1812271801&amp;client=ca-pub-5424203882835868&amp;fa=1&amp;ifi=5&amp;uci=a!5&amp;btvi=2" marginwidth="0" marginheight="0" vspace="0" hspace="0" allowtransparency="true" scrolling="no" allowfullscreen="true" data-google-container-id="a!5" data-google-query-id="CPu0odfB1vICFcHTfAodBdkO3g" data-load-complete="true" style="display: block; margin: 0px auto;"></iframe>
  (Session info: chrome=92.0.4515.159)

selenium

수차례의 삽질 끝에 결국 알아냈다.

options.add_argument('window-size=981,721')

창크기를 설정해주었다.그리고 나서

from selenium import webdriver

options = webdriver.ChromeOptions()
options.add_argument('window-size=981,721')
options.add_experimental_option("excludeSwitches", ["enable-logging"])
browser = webdriver.Chrome(options=options)
browser.get('http://zzzscore.com/1to50/')
browser.implicitly_wait(time_to_wait=5)

#전역변수
#현재 찾아야될 숫자
num = 1

def clickBtn():
    global num
    btns = browser.find_elements_by_xpath('//*[@id="grid"]/div[*]')

    for btn in btns:
        print(btn.text, end='\t')
        if btn.text == str(num):
            btn.click()
            print(True)
            num += 1
            return

while num<=50:
    clickBtn()

이렇게 추가 하고 런 돌리니까 selenium

잘된다.

혹시나 같은 에러 나는 사람이 있다면 한번 해보길 바란다.


selenium

Leave a comment