无法使用watir webdriver单击下拉框中的超链接

时间:2013-06-19 20:40:52

标签: webdriver watir-webdriver

尝试单击下拉框中的超链接时遇到错误。我尝试了几个选项(我将在下面发布),但我不断收到错误unable to locate the elementelement not visible。如果我试着等待,我会得到一个超时错误。 看起来我的代码无法找到我想要点击的元素。 奇怪的是,如果我在irb中运行命令,我可以使用文本点击链接。

所以我希望有人打电话帮助我,因为我无法弄清楚我错过了什么。

这就是我拥有的以及我想要做的事情。

我的网页上有多张卡片。我想选择第一张卡 - 这是一个下拉箭头 - 我能够做到。单击箭头后,它会显示另一个下拉框,其中包含我要单击的项目列表,具体取决于我要测试的内容。我可以单击箭头查看下拉框,但是当我尝试单击此下拉列表中的超链接时,我会收到错误。

这就是网页的样子(抱歉无法提供实际页面的链接)

cardxxxxxxxx(点击箭头),我

I would like to (drop down box.Click on arrow,I get)
  View card features
  Dispute a transaction
  Request a plastic card
  View all transactions

这里有其他一些东西。 然后我有下一张卡

cardxxxxxxxxx

在下拉和链接等方面与上面完全相同。

我希望能够点击第一张卡的下拉框(例如查看所有交易)中的超链接。如果没有上面提到的错误,我该怎么做呢?

我想最终能够说点击第二张卡并点击该卡下拉框中的超链接(这将是一个单独的测试用例)。

这是我的代码;我在firefox中尝试这个。

    $b.image(:alt, "Actionbuttondown").click
    #$b.link(:class, 'viewAllTransactions').wait_until_present
    #$b.link(:text, "View all transactions").click
    #$b.link(:class, "viewAllTransactions").click
    #$b.link(:text, "View all transactions").when_present.click
    #$b.div(:class, 'actionMenuContainer').as[0].when_present.click
    #$b.link(:text, 'View all transactions').hover
    #$b.link(:text, 'View all transactions').flash
    #$b.link(:text, 'View all transactions').when_present.click
    #$b.link(:text, 'View all transactions').click
    #$b.link(:text, "View all transactions").flash
    #$b.link(:text, "View all transactions").click
    #$b.button(:id, 'btnPages').wait_until_present
    #$b.link(:href, "/cards/details/xxxxxx-xxx/transaction_history?      card_id=xxxxxxxxxxxxx").hover
    #$b.link(:href, "/cards/details/xxxxx-xxx/transaction_history?card_id=xxxxxxxxxxxxxx").when_present.click
     $b.link(:class => 'actionMenuItems', :text => "View all transactions").click

这是页面上的html:

<div class="hiddenDetails" style="display: block;">
  <div class="actionMenuContainer">
    <div class="actionMenu">
    <h1>I would like to…</h1> 
      <div class="actionMenuIcon"><img alt="Actionbuttondown"  src="/images/actionButtonDown.png?xxxxxxxxx"></div>
        <div class="actionMenuItems"> 
          <div class="actionMenuItems" style="position: absolute; left: 1105.5px; top: 365px;  width: 177px; display: block;">
            <a href="/cards/details/xxxxxx-xxxl?card_id=xxxxxxxxxxxxx" class="viewAllTransactions">View card features</a>
            <a href="/site/dispute-transaction?account_id=xxxxxxxxxxxxx" class="viewAllTransactions">Dispute a transaction</a>
            <a href="/users/request-card/xxxxxxxxxxxxxxxxxx=" class="requestPlasticAction">Request a plastic card</a>
            <a href="/cards/details/xxxxxx-xxx/transaction_history?card_id=xxxxxxxxxxxxx" class="viewAllTransactions">View all transactions</a>
        </div>                      

感谢任何帮助。我花了很多时间试图解决这个问题而没有成功。请帮忙。


回应您的意见:

这是我正在尝试做的事情,我将包括实际的watir代码。

Go to url
Enter username password
click on a drop down box
click on hyperlink (View all transactions)

这是有问题的watir代码。

$b.image(:alt, "Actionbuttondown").click (workks and shows the drop down box).
$b.link(:text, "View all transactions").click (fails with error).

以下是我收到的错误消息。

WebDriver::Error::ElementNotVisibleError: Element is not currently visible and so may not be interacted with
[remote server] file:///C:/Users/xxxx/AppData/Local/Temp/webdriver-profile20130620-5028-1doln2f/extensions/fxdriver@googlecode.com/components/command_processor.js:7682:in `fxdriver.preconditions.visible'
[remote server] file:///C:/Users/xxxx/AppData/Local/Temp/webdriver-profile20130620-5028-1doln2f/extensions/fxdriver@googlecode.com/components/command_processor.js:10402:in `DelayedCommand.prototype.checkPreconditions_'
[remote server] file:///C:/Users/xxxx/AppData/Local/Temp/webdriver-profile20130620-5028-1doln2f/extensions/fxdriver@googlecode.com/components/command_processor.js:10421:in `DelayedCommand.prototype.executeInternal_/h'
[remote server] file:///C:/Users/xxxx/AppData/Local/Temp/webdriver-profile20130620-5028-1doln2f/extensions/fxdriver@googlecode.com/components/command_processor.js:10426:in `DelayedCommand.prototype.executeInternal_'
[remote server] file:///C:/Users/xxxx/AppData/Local/Temp/webdriver-profile20130620-5028-1doln2f/extensions/fxdriver@googlecode.com/components/command_processor.js:10366:in `DelayedCommand.prototype.execute/<'
C:/Ruby193/lib/ruby/gems/1.9.1/gems/selenium-webdriver-2.32.1/lib/selenium/webdriver/remote/response.rb:52:in `assert_ok'
C:/Ruby193/lib/ruby/gems/1.9.1/gems/selenium-webdriver-2.32.1/lib/selenium/webdriver/remote/response.rb:15:in `initialize'
C:/Ruby193/lib/ruby/gems/1.9.1/gems/selenium-webdriver-2.32.1/lib/selenium/webdriver/remote/http/common.rb:59:in `new'
C:/Ruby193/lib/ruby/gems/1.9.1/gems/selenium-webdriver-2.32.1/lib/selenium/webdriver/remote/http/common.rb:59:in `create_response'
C:/Ruby193/lib/ruby/gems/1.9.1/gems/selenium-webdriver-2.32.1/lib/selenium/webdriver/remote/http/default.rb:66:in `request'
C:/Ruby193/lib/ruby/gems/1.9.1/gems/selenium-webdriver-2.32.1/lib/selenium/webdriver/remote/http/common.rb:40:in `call'
C:/Ruby193/lib/ruby/gems/1.9.1/gems/selenium-webdriver-2.32.1/lib/selenium/webdriver/remote/bridge.rb:619:in `raw_execute'
C:/Ruby193/lib/ruby/gems/1.9.1/gems/selenium-webdriver-2.32.1/lib/selenium/webdriver/remote/bridge.rb:597:in `execute'
C:/Ruby193/lib/ruby/gems/1.9.1/gems/selenium-webdriver-2.32.1/lib/selenium/webdriver/remote/bridge.rb:362:in `clickElement'
C:/Ruby193/lib/ruby/gems/1.9.1/gems/selenium-webdriver-2.32.1/lib/selenium/webdriver/common/element.rb:54:in `click'
C:/Ruby193/lib/ruby/gems/1.9.1/gems/watir-webdriver-0.6.4/lib/watir-webdriver/elements/element.rb:131:in `click'
C:/workspace/Automated Test Scripts/trunk/MPC/defs/view_all_transactions_defs.rb:15:in `view_all_transactions'
C:/workspace/Automated Test Scripts/trunk/MPC/tests/TC22047_View_ All_Transactions.rb:97:in `test_save_for_later'

      94:   def test_save_for_later
      95:     go_to_url
      96:     enter_username_password
  =>  97:     view_all_transactions

这是我在irb中尝试过的作品

browser3.image(:alt, "Actionbuttondown").click
browser3.link(:text, "View all transactions").click

希望现在更有意义,你可以指出我正确的方向。

0 个答案:

没有答案
相关问题