Maximize Browser Window

此SeleniumLibrary 关键字 Maximize Browser Window 只在不是headless模式下起作用,headless模式下,浏览器窗口还是默认大小,所以有些元素就会找不到

设置参数 start-maximized

经尝试,这种方法也不可取

添加参数window-size

Call Method    ${driver_options}    add_argument    --window-size=1960,1000

会报错

set window size

Set Window Size    ${1400}   ${600}

这种方法ok

详细代码

OpenUrlHeadless
[Arguments] ${bro} ${url}
${driver_options}= Evaluate sys.modules['selenium.webdriver'].${bro}Options() sys, selenium.webdriver
Call Method ${driver_options} add_argument --headless
Call Method ${driver_options} add_argument --disable-dev-shm-usage
Call Method ${driver_options} add_argument --no-sandbox
Call Method ${driver_options} add_argument disable-gpu # 可选项:禁用gpu,可以解决一些莫名的问题
# ${winsow_size} set variable window-size=1960*1080
# Call Method ${driver_options} add_argument ${winsow_size}
${currentpath} evaluate os.getcwd() os #获取到项目所在目录
${prefs} create dictionary download.default_directory=${currentpath}${/}Doc${/} download.prompt_for_download=False
log ${prefs}
Call Method ${driver_options} add_experimental_option prefs ${prefs}
${options}= Call Method ${driver_options} to_capabilities
Create Webdriver ${bro} desired_capabilities=${options}
Set Window Size ${1400} ${600}
Go To ${url}

可参考链接​​groups.google.com/g/robotfram…​