English 中文(简体)
十二. 定期网络司机
原标题:Selenium WebDriver with Perl

我试图用佩雷尔装具装束力的塞伦ium驾驶员,由于缺乏实例和文件,我进入了一些路障。 我对如何做一些基本事情作了说明,但我似乎正在讨论其他一些简单的问题,如在使用<代码>的网页上确认案文:司机<>/代码>包。

如果我试图这样做的话:

$sel->get("https://www.yahoo.com/" );
$ret = $sel->find_element("//div[contains( text(), Thursday, April 26, 2012 )]");

我收到一个信息,即该要素可以找到。 我正在使用xpath,因为驾驶员包裹似乎在寻找案文方面有分点,至少我已经发现。

如果我的食堂是错的,或者如果有人知道更好的方式,那将非常有益。 我的点子也存在问题,但似乎这样容易,而且正在对我进行点击。

问题回答

网页上的定本,并将该文本与一些使用 Sel的“已知良好价值”进行比较:

档案: SomeWebApp.pm

package SomeWebApp;

sub get_text_present {

    my $self = shift;
    my $target = shift;
    my $locator = shift;

    my $text = $self->{driver}->find_element($target, $locator)->get_text();

    return $text;

}

您的试稿中有些地方:测试。

my $text = $some_web_app->get_text_present("MainContent_RequiredFieldValidator6", "id");

以上是用定位仪确定的定位办法确定的按点数确定的元件,并将之储存在可变文本中。 然后,你可以利用这一方法比较/验证所需/需要。

https is a tad slower loading than http. Although WebDriver is pretty good about waiting until it s figured out that the requested page is fully loaded, maybe you need to give it a little help here. Add a sleep(2); after the get() call and see if it works. If it does, try cutting down to 1 second. You can also do a get_title call to see if you ve loaded the page you think you have.

另一种可能性是,你的文本目标与页上的目标完全相同。 你可以尝试一字,如“4月”一字,看你是否受到打击,然后扩大,直到你发现错话(例如,这种扼杀实际上有一条新线或打破这条线?) 如何建立超文本实体,如非开拓性空间? 另外,在四分五裂的任何地方,你们都在寻找这一案文(所有儿童的文本据称都被压缩,然后进行搜查)。 这样做的可能性比根本得不到任何东西都大得多,但值得了解。





相关问题
Why does my chdir to a filehandle not work in Perl?

When I try a "chdir" with a filehandle as argument, "chdir" returns 0 and a pwd returns still the same directory. Should that be so? I tried this, because in the documentation to chdir I found: "...

How do I use GetOptions to get the default argument?

I ve read the doc for GetOptions but I can t seem to find what I need... (maybe I am blind) What I want to do is to parse command line like this myperlscript.pl -mode [sth] [inputfile] I can use ...

Object-Oriented Perl constructor syntax and named parameters

I m a little confused about what is going on in Perl constructors. I found these two examples perldoc perlbot. package Foo; #In Perl, the constructor is just a subroutine called new. sub new { #I ...

Where can I find object-oriented Perl tutorials? [closed]

A Google search yields a number of results - but which ones are the best? The Perl site appears to contain two - perlboot and perltoot. I m reading these now, but what else is out there? Note: I ve ...

热门标签