[Selenium] Element is not clickable,Other element would receive the click

先貼一下Robot Framework腳本:

*** Settings ***
# this is the only place where we have to hard-code a path;
# when config.py is loaded it will alter the path to include the resources folder.
Variables   ../resources/config.py
Library     PageObjectLibrary
Library    SeleniumLibrary    run_on_failure=Capture Page Screenshot    screenshot_root_directory=${CURDIR}\selenium-screenshot        
Suite Setup       SeleniumLibrary.Open Browser    ${CONFIG["Indexpage"]}    ${BROWSER1} 
Suite Teardown    SeleniumLibrary.Close All Browsers

*** Variables ***
${BROWSER}    chrome
${BROWSER1}    headlesschrome

*** Test Cases ***
車場首頁
    [Setup]    Go To Page    ParkIndex
    [Tags]    P1
    check_page_element
    click_payment_text_and_back    # 點擊繳費說明
    The Current Page Should Be    ParkIndex
    input_plateNo        # 輸入車牌號:京111111,點擊查費按鈕,參數爲是否開啓引導綁車彈窗
    The Current Page Should Be    FeeDetails

公司採用的是 Page Object 設計模式來組織GUI層級的測試用例,其中../resources/config.py是自定義的變量文件,用來切換腳本運行環境, PageObjectLibrary是用來實現Page Object模式的一個庫,用下來之後發現和項目需求有些不兼容,後續進行了一些修改;

調試腳本時,使用chrome都是通過的,然而實際在Jenkins slave上是採用headlesschrome來跑腳本,但是怎麼跑都會報同樣的錯誤:

20190110 18:50:15.205 : FAIL : WebDriverException: Message: unknown error: Element <button class="s_btn_lg font16" id="paybtn">...</button> is not clickable at point (400, 529). Other element would receive the click: <div class="cofco-footer_fixContent">...</div>
  (Session info: headless chrome=71.0.3578.98)
  (Driver info: chromedriver=71.0.3578.80 (2ac50e7249fbd55e6f517a28131605c9fb9fe897),platform=Windows NT 10.0.17134 x86_64)

後來發現headlesschrome進行實例化瀏覽器時默認是以全屏模式,而chrome則是以768*1024,這就導致我定位的元素被遮擋,無法定位,所以我對腳本進行了優化,只需要修改Suite Up爲:

Suite Setup       BuiltIn.Run Keywords    SeleniumLibrary.Open Browser    ${CONFIG["Indexpage"]}    ${BROWSER1}    AND    SeleniumLibrary.Set Window Size    768    1024

這樣再去執行腳本就不會報錯了。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章