我从robotframework开始,并且我无法为Google搜索按钮获取正确的选择器。我在做什么错了?
*** Settings ***
Documentation This is a basic test
Library SeleniumLibrary
*** Variables ***
${url} https://www.google.com
${browser} chrome
${text} css:input[name=q]
${search_button} css:input[name=btnK]
${expected_result} Test
*** Test Cases ***
User fill in the Search text box
[Documentation] The user search 'Test'
open browser ${url} ${browser}
wait until page contains ${url}
input text ${text} test
click button ${search_button}
wait until page contains ${expected_result}
sleep 5s
close browser
答案 0 :(得分:2)
除了点击搜索按钮的最后一部分之外,所有内容似乎都很完美。缩进的导入对我来说也很奇怪。可能只有我一个人,但是我在VS Code的那一行上出错了。一旦我解决了(只是删除缩进)。单击搜索按钮的实际问题将通过硒库的Press Keys
关键字解决。当我们在搜索框中输入内容时,自动提示会覆盖搜索按钮。无需摆脱下拉菜单,只需按Enter键即可,如下面的代码所示-
User fill in the Search text box
[Documentation] The user search 'Test'
open browser ${url} ${browser}
wait until page contains ${url}
input text ${text} test
Press keys ${text} RETURN
wait until page contains ${expected_result}
sleep 5s