จะดาวน์โหลดไฟล์ด้วย phantomJS โดยใช้ Robot Framework ได้อย่างไร

ฉันใช้ Robot Framework กับ PhantomJS (เบราว์เซอร์ที่ไม่มีส่วนหัว) และต้องการดาวน์โหลดไฟล์ แต่ PhantomJS ไม่มีความสามารถหรือตัวเลือกที่ต้องการในการตั้งค่ากำหนดเหมือนกับที่เราทำใน Chrome กำลังมองหาคำแนะนำหรือตัวเลือกอื่น ๆ ในการดาวน์โหลดไฟล์ CSV โดยใช้ PhantomJS พร้อม Robot Framework


person Madasu    schedule 28.11.2017    source แหล่งที่มา
comment
เหตุผลใดที่คุณชอบ PhantomJS มากกว่า Chrome สำหรับการทำงานของเบราว์เซอร์แบบไม่มีหัว Chrome เวอร์ชัน 59 รองรับ Mac และ Linux และมีการเพิ่ม Windows ในเวอร์ชัน 60 เวอร์ชันปัจจุบันคือ 62   -  person A. Kootstra    schedule 28.11.2017
comment
ฉันไม่เคยลองใช้เบราว์เซอร์ Chrome headless โดยใช้ PhantomJS เนื่องจากฉันต้องเรียกใช้โค้ดนี้บนเซิร์ฟเวอร์ ขอบคุณ   -  person Madasu    schedule 29.11.2017


คำตอบ (1)


ดังที่คุณเน้นว่าการดาวน์โหลดไฟล์ไม่ใช่ปัญหา ด้านล่างนี้คุณจะพบตัวอย่าง Robot Script ที่เริ่ม Chrome ในโหมด Headless

*** Settings ***
Library    Selenium2Library

Suite Teardown    Close All Browsers

*** Test Cases ***
Headless Chrome - Open Browser
    ${chrome options}=    Evaluate    sys.modules['selenium.webdriver'].ChromeOptions()    sys, selenium.webdriver
    ${prefs}    Create Dictionary   credentials_enable_service=${false}                 # Verberg de sla wachtwoord op pop-up

    Call Method    ${chrome_options}    add_experimental_option    prefs    ${prefs}
    Call Method    ${chrome options}    add_argument    start-maximized                 # Open de browser in gemaximaliseerd.
    Call Method    ${chrome_options}    add_argument    --headless
    Call Method    ${chrome_options}    add_argument    --disable-gpu    
    Call Method    ${chrome_options}    add_argument    --window-size\=1920,1080
    Create Webdriver    Chrome    chrome_options=${chrome options}

    Go To    http://cnn.com

    Capture Page Screenshot

ในกรณีที่คุณต้องการทำงานในโหมด headless ในสภาพแวดล้อมแบบ Grid ให้ใช้ตัวอย่างต่อไปนี้:

*** Settings ***
Library    Selenium2Library

Suite Teardown    Close All Browsers

*** Test Cases ***
Headless Chrome - Create Webdriver2
    ${chrome options} =     Evaluate    sys.modules['selenium.webdriver'].ChromeOptions()    sys, selenium.webdriver
    Call Method    ${chrome_options}   add_argument   --window-size\=1920,1080
    Call Method    ${chrome options}   add_argument   --start-maximized
    Call Method    ${chrome options}   add_argument   --headless
    Call Method    ${chrome options}   add_argument   --disable-gpu
    ${options}=     Call Method     ${chrome_options}    to_capabilities      

    Create Webdriver    Remote   command_executor=http://localhost:4444/wd/hub    desired_capabilities=${options}

    Go to     http://cnn.com

    Capture Page Screenshot 
person A. Kootstra    schedule 29.11.2017
comment
เมื่อฉันลองใช้โค้ดของคุณ (รูปแบบแรก) มันทำให้ฉันมีข้อผิดพลาด unrecognized Chrome version: HeadlessChrome/62.0.3202.94 - person Brandon Olson; 01.12.2017
comment
ไม่เป็นไร ปัญหาอยู่ที่ ChromeDriver 2.29 และต่ำกว่าไม่รองรับ Chrome แบบไม่มีส่วนหัว - person Brandon Olson; 01.12.2017