
到目前为止我取得的成就:
>找到硒的链接并点击它
>等待警报出现
>从警报中获取字符串,但不从文本字段中获取字符串
码
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 promptselect undef,8.00;# get the prompt default inputmy $input = $d->execute_script('return window.last_prompt.input;'); 总结 以上是内存溢出为你收集整理的如何使用selenium webdriver在perl的警报/提示/对话框中获取文本?全部内容,希望文章能够帮你解决如何使用selenium webdriver在perl的警报/提示/对话框中获取文本?所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)