在javascript中,Selenium元素在点(chrome)处不可单击
我是Selenium新手,正在Browserstack上运行Selenium脚本 一切正常,直到我到达页面底部的10% 我得到以下错误: 未捕获WebDriverError:Appium错误:未知错误:元素在点(20324)处不可单击。其他 元素将收到单击:。。。 (会话信息:chrome=58.0.3029.83) (驱动程序信息:chromedriver=2.29.461571(8a88bbe0775e2a23afda0ceaf2ef7ee74e822cc5),平台=Linux 3.19.8-100.fc20.x86_64(x86_64) 这是我的代码:在javascript中,Selenium元素在点(chrome)处不可单击,javascript,selenium,ui-automation,browserstack,Javascript,Selenium,Ui Automation,Browserstack,我是Selenium新手,正在Browserstack上运行Selenium脚本 一切正常,直到我到达页面底部的10% 我得到以下错误: 未捕获WebDriverError:Appium错误:未知错误:元素在点(20324)处不可单击。其他 元素将收到单击:。。。 (会话信息:chrome=58.0.3029.83) (驱动程序信息:chromedriver=2.29.461571(8a88bbe0775e2a23afda0ceaf2ef7ee74e822cc5),平台=Linux 3.19.8
describe.only(testTitle, function () {
before(function () {
driver = driverConfiguration.getDriverConfiguration(testTitle, 'chrome')
})
after(function (done) {
driver.quit().then(done)
})
it('Sample tests', function (done) {
driver.get('https://www.test.com').then(function(){
driver.findElement(webdriver.By.name('cardNumber')).sendKeys('0000000000').then(function(){
driver.findElement(webdriver.By.id('billingLine1')).sendKeys('test');
driver.findElement(webdriver.By.id('billingLine2')).sendKeys('test');
driver.findElement(webdriver.By.id('billingCity')).sendKeys('San Jose');
driver.findElement(webdriver.By.id('agree')).click(); // ERROR!!!!!
}).then(function() {
driver.quit().then(done);
})
});
})
})
当我执行以下操作时:
// return driver.wait(function() {
// return driver.findElement(webdriver.By.id('agree')).isDisplayed();
// }, 1000);
这是真的。元素是可见的
在三星Galaxy S8上使用Chrome
我不知道如何解决这个问题。继续上面的评论 我也遇到了这个问题,当时我需要单击一个按钮,但它在屏幕上不可见(但是,它被代码检测到)。 为了解决这个问题,我使用WebDriver的
executeScript()
方法在页面上运行一些JavaScript来滚动,直到我的按钮出现为止
driver.executeScript(`
var target = document.getElementById('agree');
var tarTop = target.getBoundingClientRect().top;
document.body.scrollTop = tarTop;
`);
如果要向滚动添加超时,可以尝试driver.executeAsyncScript()
,以确保页面首先到达其目标。此时,您将使用async/await
await driver.executeAsyncScript(`
var callback = arguments[arguments.length - 1];
var target = document.getElementById('agree');
var tarTop = target.getBoundingClientRect().top;
document.body.scrollTop = tarTop;
setTimeout(()=>{ callback( true ); }, 1500);
`).then((data)=>{
return data;
});
从上面的评论继续 我也遇到了这个问题,当时我需要单击一个按钮,但它在屏幕上不可见(但是,它被代码检测到)。 为了解决这个问题,我使用WebDriver的
executeScript()
方法在页面上运行一些JavaScript来滚动,直到我的按钮出现为止
driver.executeScript(`
var target = document.getElementById('agree');
var tarTop = target.getBoundingClientRect().top;
document.body.scrollTop = tarTop;
`);
如果要向滚动添加超时,可以尝试driver.executeAsyncScript()
,以确保页面首先到达其目标。此时,您将使用async/await
await driver.executeAsyncScript(`
var callback = arguments[arguments.length - 1];
var target = document.getElementById('agree');
var tarTop = target.getBoundingClientRect().top;
document.body.scrollTop = tarTop;
setTimeout(()=>{ callback( true ); }, 1500);
`).then((data)=>{
return data;
});
您忽略了问题中错误消息最重要的部分 其他元素将收到单击:
…
部分中的元素就是阻止单击的元素。正如您所发现的,Selenium报告元素已显示/可见。此错误消息只是说明当Selenium尝试单击该元素时,另一个元素阻止了单击。如果您查看阻塞元素的HTML并在页面的HTML中搜索,您应该能够识别该元素。根据我的经验,它是一个对话框,或者可能是页面底部的一个横幅,等等。有时需要关闭它,有时需要向下/向上滚动一点,以便从阻塞UI后面获得所需的元素。您忽略了问题中最重要的错误消息部分
其他元素将收到单击:
…
部分中的元素就是阻止单击的元素。正如您所发现的,Selenium报告元素已显示/可见。此错误消息只是说明当Selenium尝试单击该元素时,另一个元素阻止了单击。如果您查看阻塞元素的HTML并在页面的HTML中搜索,您应该能够识别该元素。根据我的经验,它是一个对话框,或者是页面底部的横幅,等等。有时候你需要关闭它,其他时候,您需要向下/向上滚动一点,以从阻塞UI后面获取所需的元素。我以前遇到过这个错误,但我能够通过确保单击时元素在屏幕上可见来解决它。当我尝试执行此代码时:`//return driver.wait(function(){//return driver.findElement(webdriver.By.id('agree')).isDisplayed();//},1000);`它确实表示true。即元素是可见的。不确定如何解决此问题:(没有静态编码滚动。这就是我最后使用driver.executeScript()所做的事情)--我不知道为什么元素对代码可见时必须出现在屏幕上,但它确实让它工作了:)可能的重复我以前遇到过这个错误,但我能够通过确保元素在单击时在屏幕上可见来解决它。当我试着执行此代码时:`//return driver.wait(function(){//return driver.findElement(webdriver.By.id('agree')).isDisplayed();//},1000);`它确实表示true。即元素是可见的。不确定如何解决此问题:(没有静态编码滚动。这就是我最后使用driver.executeScript()所做的事情)--我不知道为什么元素在代码可见时必须出现在屏幕上,但它确实让它工作了:)我使用了这个元素的可能副本,它解决了我的问题:driver.executeScript(`var target=document.getElementById('agree').scrollIntoView();`);感谢@DougI使用了这些输入,它解决了我的问题:driver.executeScript(`var target=document.getElementById('agree')。scrollIntoView();`);谢谢你的输入@DougYup你完全正确。我发现使用相同的东西,我使用了其他的“div”并且成功了!谢谢@JeffCYup你完全正确。我发现使用相同的东西,我使用了其他的“div”并且成功了!谢谢@JeffC