Nightwatch.js 在执行 .setValue() 时无法识别 XPath/CSS 选择器

Nightwatch.js can't recognize XPath/CSS selector while executing .setValue()

我正在尝试 运行 一个 Nightwatch.js 脚本,它可以让我通过 Google 高级搜索来搜索某些内容。这是我的脚本:

'Google advanced search'(browser){
    const value = 'apple';
    const searchBar = 'name="as_q';
    
    
    browser
        .url('https://www.google.com/advanced_search')
        .setValue(searchBar, value) 
        .saveScreenshot('tests_output/google.png')
}

我在尝试 运行 脚本时遇到 .setValue() 问题,我总是收到以下错误:

NoSuchElementError: An error occurred while running .click() command on <class="jfk-button jfk-button-action dUBGpe">: (Session info: chrome=85.0.4183.121), (Driver info: chromedriver=85.0.4183.87 (cd6713ebf92fa1cacc0f1a598df280093af0c5d7-refs/branch-heads/4183@{#1689}),platform=Windows NT 10.0.19041 x86_64); invalid selector: An invalid or illegal selector was specified {"status":-1,"state":"","code":"","value":{"message":"invalid selector: An invalid or illegal selector was specified","error":[" (Session info: chrome=85.0.4183.121)"," (Driver info: chromedriver=85.0.4183.87 (cd6713ebf92fa1cacc0f1a598df280093af0c5d7-refs/branch-heads/4183@{#1689}),platform=Windows NT 10.0.19041 x86_64)"]},"errorStatus":32,"error":"The supplied argument was an invalid selector (e.g. XPath/CSS). – invalid selector: An invalid or illegal selector was s...","httpStatusCode":200} at processTicksAndRejections (internal/process/task_queues.js:97:5)

基本上它告诉我我使用的选择器 (XPath/CSS) 由于某种原因无效。 选择器来自页面中的以下元素:

<input class="jfk-textinput" value="" autofocus="autofocus" id="xX4UFf" name="as_q" type="text">

有什么办法可以解决这个问题吗?提前谢谢你。

您的搜索栏选择器有误 使用 '.jfk-textinput' 或 '#xX4UFf'

 'Google advanced search'(browser){
        const value = 'apple';
        const searchBar = '.jfk-textinput';
        
        
        browser
            .url('https://www.google.com/advanced_search')
            .setValue(searchBar, value) 
            .saveScreenshot('tests_output/google.png')