Xpath Codeception-单击简单链接
如何通过CodeceptionXpath Codeception-单击简单链接,xpath,codeception,Xpath,Codeception,如何通过CodeceptionAcceptanceTesterman点击简单链接 class_name: AcceptanceTester modules: enabled: - WebDriver - \Helper\Acceptance config: WebDriver: url: 'http://mysite.local' browser: 'firefox' windowSi
AcceptanceTester
man点击简单链接
class_name: AcceptanceTester
modules:
enabled:
- WebDriver
- \Helper\Acceptance
config:
WebDriver:
url: 'http://mysite.local'
browser: 'firefox'
windowSize: '1024x768'
我正在努力:
public function somePage(AcceptanceTester $I)
{
$I->amOnPage('/');
$I->click('Some page', '//a[href="/some_page.html"]');
}
但接下来的信息是:
...
CSS or XPath element with '//a[href="/some_page.html"]' was not found.
...
这是一个HTML结构:
<section id="products-anchor" class="products-list">
<div class="container">
<ul class="products">
***
<li class="">
<h3>
<a href="/some_page.html"> Some page </a>
</h3>
<p>
<a href="/some_page.html"></a>
</p>
<p>
<a href="/some_page.html">Text for some page...</a>
</p>
<p></p>
</li>
***
</ul>
</div>
</section>
***
-
***
这是一种HTML结构:
<section id="products-anchor" class="products-list">
<div class="container">
<ul class="products">
***
<li class="">
<h3>
<a href="/some_page.html"> Some page </a>
</h3>
<p>
<a href="/some_page.html"></a>
</p>
<p>
<a href="/some_page.html">Text for some page...</a>
</p>
<p></p>
</li>
***
</ul>
</div>
</section>
***
-
***
您可以在这里简单地使用用户定位器类。请检查下面的代码片段。我使用了相同的函数调用。考虑一下,我传递的元素包含了来自我的CEPT文件的URL。
使用\Codeception\Util\Locator;类名{
公共函数名称($strSomeVar,$selectorUrl){
}
这可能对你有帮助。
这里你可以简单地使用定位器类。请检查下面的代码段。我已经使用了相同的但使用函数调用。考虑我正在传递那个元素包含从我的CEPT文件中的URL。 使用\Codeception\Util\Locator;类名{ 公共函数名称($strSomeVar,$selectorUrl){ }这可能会对您有所帮助。您使用了错误的xpath,应该是:
$I->单击('Some page','//a[@href=“/Some_page.html”]”);
所以你在href前面缺少@
请注意,如果您拥有的此类链接数量超过了使用此链接访问第一个链接的数量:
$I->click('Some page','(//a[@href="/some_page.html"])[1]');
您使用了错误的xpath,应该是:
$I->单击('Some page','//a[@href=“/Some_page.html”]”);
所以你在href前面缺少@
请注意,如果您拥有的此类链接数量超过了使用此链接访问第一个链接的数量:
$I->click('Some page','(//a[@href="/some_page.html"])[1]');
希望这会对你有所帮助。我不确定你是否必须指出h3,但我很确定这会起作用
$I->click(['xpath'=>'//ul/li/h3/a[@href=“/some_page.html”]]);希望这会对您有所帮助。我不确定您是否必须指出h3,但我非常确定这会起作用 $I->单击(['xpath'=>'//ul/li/h3/a[@href=“/some_page.html”]')