Selenium 当isExisting为true时,无法单击按钮;IsDisplayInViewport为true,但WebDrivero中元素的waitForDisplayed超时

Selenium 当isExisting为true时,无法单击按钮;IsDisplayInViewport为true,但WebDrivero中元素的waitForDisplayed超时,selenium,automated-tests,mocha.js,webdriver-io,Selenium,Automated Tests,Mocha.js,Webdriver Io,脚本因此错误而失败。 错误:30000ms后仍不显示元素(“.WONDERESC”) 尝试了Xpath、(相对、固定、text()}和CSS选择器的不同组合,但未单击按钮。代码块中的登录按钮div: <div> <div class="WONDERBSC" role="form"> <div> <div class="WONDERJ1B" data

脚本因此错误而失败。 错误:30000ms后仍不显示元素(“.WONDERESC”)

尝试了Xpath、(相对、固定、text()}和CSS选择器的不同组合,但未单击按钮。代码块中的登录按钮div:

<div>
    <div class="WONDERBSC" role="form">
        <div>
            <div class="WONDERJ1B" data-automation-id="userName">
                <div class="TOM-Label WONDERP1B"
                    title="Username">Username</div>
                <input type="text"
                        class="TOM-TextBox WONDERM1B" aria-label="Username">
                    <button type="button" class="TOM-Button WONDERN1B"/>
            </div>
        </div>
            <div>
                <div class="WONDERJ1B"
                    data-automation-id="password">
                    <div class="TOM-Label WONDERP1B" title="Password">Password</div>
                    <input type="password" class="TOM-PasswordTextBox WONDERM1B" aria-label="Password">
                        <button type="button" class="TOM-Button WONDERN1B"/>
                </div>
            </div>
                <button type="button"
                        class="WONDERESC"
                        data-automation-id="goButton">Sign In</button>
    </div>      
</div>
 

用户名
密码
登录
请建议解决方法-其他条件也满足-可见性真实,显示块,不透明度不为零

谢谢,
Tan

如果元素未显示,则必须使其可见

案例1 该元素需要一些时间才能自动显示 在这种情况下,可以使用webdriver wait WebDriverWait wait=新的WebDriverWait(驱动程序,持续时间秒(10)); wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath(“xxxx”))

案例2 元素在一些交互(如鼠标移动、单击或键入)后可见
然后您必须使用selenium执行该操作。对于鼠标移动,您可以使用操作类,正如注释中所述,您使用的选择器无效

假设您拥有最新的webdriveriov6,下面的内容非常有用

//打开页面
browser.url('https://impl.workday.com/wday/authgwy/accenture_dpt2/login.htmld?redirect=n')
const form=$('[data automation id=“authPanel”][role=“form”]')
//确保表单可见
expect(form.tobevible)
//定义表单数据
常量formData=[{
id:'用户名',值:'测试'
}, {
id:'password',值:'password'
}]
//填表
formData.forEach(f=>{
表单.$(`[data automation id=“${f.id}”]input`).设置值(f.value)
})
//提交表格
表单。$(“按钮[data automation id=“goButton”]”)。单击()
//确保错误消息存在
常量errorMessage=$(“[data automation id=“alertMessage”]”)
expect(errorMessage).tobevicible()
expect(errorMessage).toHaveTextContaining('无效用户名或密码')

请共享您的代码。感谢您的考虑和。@ChristianBaumann感谢您的建议-编辑了问题。对于代码-您想看到xpath-css选择器的试用情况吗?请共享正在运行的网站。如果您的网站是私有的,那么就共享一个类似的网站。感谢@MikeG.的回复,-HTML代码块已经共享。al因此,当使用自动化脚本加载页面时,HTML没有变化。我已经验证了选择器是否正确,并且在脚本停止时唯一地标识了元素(通过添加60秒延迟)。HTML块不是一个页面。可能在样式、js等方面存在一些问题。这还不够。谢谢@rahul的建议。给出的建议在ui上不起作用。谢谢,对代码的回答。它在wdIO-6中运行良好,即使是我使用的选择器。问题是我使用的wdIO5。-这不起作用。$('button[data automation id=“goButton”]”。单击()。谢谢。