如何使用selenium webdriver在perl的警报/提示/对话框中获取文本
发布时间:2020-12-16 06:21:30 所属栏目:大数据 来源:网络整理
导读:我想在下面的图片中找到一个字符串.它位于警报,提示或对话框内.我的代码是用Perl编写的,我使用Selenium Webdriver来浏览页面. 到目前为止我取得的成就: 找到硒的链接并点击它 等待警报出现 从警报中获取字符串,但不从文本字段中获取字符串 码 my $copy_elem
我想在下面的图片中找到一个字符串.它位于警报,提示或对话框内.我的代码是用Perl编写的,我使用Selenium Webdriver来浏览页面.
到目前为止我取得的成就: >找到硒的链接并点击它 码 my $copy_elem = wait_until { $d->find_element_by_id('clipboard-link'); }; $copy_elem->click; select undef,undef,8.00; my $alert = wait_until { $d->get_alert_text; }; $alert输出是“复制链接” 所以我想要的文本在alert的文本字段中.使用get_alert_text我只获取Alert字符串,但不获取文本字段内容.我在网上搜索了答案,看到人们使用窗口句柄切换到警报.我试图在Selenium Webdriver的文档中寻找类似的功能: CPAN Selenium Webdriver Docu with list of functions 我尝试获取窗口句柄并将它们加载到一个数组中,但它没有获得警报的第二个窗口句柄. get_current_window_handle也不起作用.我使用phantomjs和chrome作为浏览器.据我所知,没有driver.switchto().alert();对于perl. 解决方法
一种方法是使用脚本注入覆盖页面中的
prompt函数:
# override the prompt function $d->execute_script('window.prompt=function(message,input){window.last_prompt = {message: message,input: input}};'); # trigger a prompt select undef,8.00; # get the prompt default input my $input = $d->execute_script('return window.last_prompt.input;'); (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |