处理多个窗口时出现Perl Selenium错误

时间:2016-11-23 05:38:13

标签: perl selenium

我正在尝试循环下拉值,但在循环中,当我选择一个值并下载文件时,我得到一个新窗口,在关闭该窗口后,我的webelement没有显示其余的下拉值。看起来它没有被设置。请帮忙。请看下面的代码:

my $dropdown = $driver->find_element_by_xpath(".//span[\@id='pk3']/select[\@id='Key']");
my $child = $driver->find_child_elements($dropdown, ".//option");

foreach my $option(@$child){

    my $text = $option->get_text();

    print $text."\n";

    if($text eq ("5103" || "5102" || "5100") ){

        $counter ++;
        $option->click;
        $driver->pause(8000);
        $driver->find_element_by_xpath(".//*[\@id='ms60']/span/span/table/tbody/tr/td[29]/a")->click;
        print "Clicked on Export \n";
        #Here a new window opens and file is dowloaded to downloads folder
        my $handles = $driver->get_window_handles;
        $driver->switch_to_window($handles->[1]);
        $driver->pause(5000);
        #This closes the new window which got opened above
        $driver->close();
        #Back to the main site page
        $driver->switch_to_window($handles->[0]);
        $driver->pause();
        print "File must have got downloaded \n";
        $driver->pause(10000);

    }
    else
    {
        print "This $text is not the one \n";
        next;

    }
}
  

当前输出:它将值打印到5103并下载该文件   但之后它开始打印HASH(0x3e8b24c)等值。   所以一切都在其他地方。

请注意,我使用的是Selenium :: Remote :: Driver模块。

0 个答案:

没有答案
相关问题