【问题标题】:Codeception - click simple linkCodeception - 点击简单链接
【发布时间】:2017-03-17 10:07:24
【问题描述】:

如何通过 Codeception AcceptanceTester 人点击简单链接 <a href="/some_page.html">Some page</a>

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.
...

【问题讨论】:

    标签: xpath codeception


    【解决方案1】:

    你使用了错误的xpath,应该是:

    $I->click('Some page','//a[@href="/some_page.html"]');

    所以你在href前面缺少@。

    如果您拥有的此类链接比您可以访问的第一个链接还多:

    $I->click('Some page','(//a[@href="/some_page.html"])[1]');
    

    【讨论】:

      【解决方案2】:

      这是 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>
      

      【讨论】:

        【解决方案3】:

        您可以在这里简单地使用定位器类。请检查下面的sn-p。我使用了相同但使用功能调用。考虑到我传递的元素包含来自我的 cept 文件的 URL。

        使用\Codeception\Util\Locator;类类名{

        公共函数 fun_name($strSomeVar, $selectorUrl){

            $I->see( $strSomeVar, Locator::href( $selectorUrl ) );
            $I->click( Locator::href( $selectorUrl ) );
        
        }
        

        }

        这可能对你有帮助。

        【讨论】:

          【解决方案4】:

          希望这会对您有所帮助。我不确定你是否必须指出 h3,但我很确定这会起作用。

          $I->click(['xpath'=> '//ul/li/h3/a[@href="/some_page.html"]']);

          【讨论】:

            猜你喜欢
            • 1970-01-01
            • 2023-04-08
            • 1970-01-01
            • 1970-01-01
            • 2023-04-01
            • 1970-01-01
            • 1970-01-01
            • 2016-08-14
            • 1970-01-01
            相关资源
            最近更新 更多