如何从JavaScript引发异常';如果通过Selenium'执行,则调用;s executeAsyncScript
我正在使用SeleniumWebDriver自动化一些脚本。大部分功能都是使用JavaScript端点执行的,我无法将此逻辑移动到Python:如何从JavaScript引发异常';如果通过Selenium'执行,则调用;s executeAsyncScript,javascript,asynchronous,selenium,selenium-webdriver,Javascript,Asynchronous,Selenium,Selenium Webdriver,我正在使用SeleniumWebDriver自动化一些脚本。大部分功能都是使用JavaScript端点执行的,我无法将此逻辑移动到Python: // Python Selenium script data = self.driver.execute_async_script('selenium.get_data(arguments)') // JavaScript placed somewhere on the page tested selenium.get_data = functio
// Python Selenium script
data = self.driver.execute_async_script('selenium.get_data(arguments)')
// JavaScript placed somewhere on the page tested
selenium.get_data = function(args) {
$.ajax({
url:'http://servername/ajax_data',
success: function(data) {
args[0](data);
},
error: function(data) {
// here I would like to notify selenium that everything is broken
}
});
};
JavaScript中通常有一点我知道一切都已经被破坏了,我想在Selenium脚本中提出异常。
当然,我可以等待超时,但是我的脚本超时很长,我无法在错误消息中提供额外的调试信息
我已经检查了文档()和测试的源代码()
目前,我正在使用变通方法,这似乎不太好:
error: function(data) {
window.alert(JSON.stringify(data));
}
你知道更好的解决办法吗