使用watir-webdriver查找动态元素

时间:2014-10-02 20:54:23

标签: ruby selenium watir-webdriver

我正在自动化的应用程序有一个“to ...”按钮,打开一个悬停弹出窗口,其中包含我需要完成填写主窗体的一些选择/选项。

首先,按下“to ...”按钮后,弹出“神奇地”弹出,例如,我不知道是什么代码打开它。与to_button关联的唯一JavaScript是:

一旦打开新窗口,就会出现一个下拉列表,其中一个从列表框中选择一个类别,在选择类别后,新窗口将更新为该类别中的用户列表。

如何捕获屏幕,找出字段的名称/ ID,然后单击“完成”按钮(将其带回主屏幕,其中“To ...”然后选中值。

以下是相关的代码部分:

<!-- Recipient List---------------------------------------------------------------------------------------------------- -->
    <div class="sam-block  clearfix">
        <!-- open selection screen -->
        <div class="label">

            <a style="clear: both;margin-top:5px;" href="#" class="secondaryButtonSmall" id="to_button">To...</a>

        </div>
        <!-- display selected recipients -->
        <div class="field">
            <div id="NotificationRecipientContainer">

            </div>
            <!-- Map ---------------------------------------------------------------------------------------------------------------- -->
            <div id="selectMapLink">

            </div>
        </div>
        <!-- hidden window for selection -->
        <div>
            <div id="RecipientSelectionWindow" style="overflow:auto;display:none"><div style="display:inline-block;margin-left:40%;margin-top:20%;"><div class="loadingInline">Loading...</div></div></div><script>
    jQuery(function(){jQuery("#RecipientSelectionWindow").kendoWindow({"modal":true,"iframe":false,"draggable":true,"pinned":false,"title":"Send Message To:","resizable":false,"content":null,"width":850,"actions":["Close"]});});
</script>

以下是Selenium(我没有使用的工具)提出的内容:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head profile="http://selenium-ide.openqa.org/profiles/test-case">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<link rel="selenium.base" href="https://connect.blackboardconnect.com/" />
<title>New Test</title>
</head>
<body>
<table cellpadding="1" cellspacing="1" border="1">
<thead>
<tr><td rowspan="1" colspan="3">New Test</td></tr>
</thead><tbody>
<tr>
    <td>open</td>
    <td>/Notification/LoadNewMessage?messageStatus=Draft&amp;messageType=Emergency#</td>
    <td></td>
</tr>
<tr>
    <td>click</td>
    <td>id=to_button</td>
    <td></td>
</tr>
<tr>
    <td>click</td>
    <td>//div[@id='selectionSourceContent']/div/span/span/span</td>
    <td></td>
</tr>
<tr>
    <td>click</td>
    <td>css=li.k-item.k-state-hover</td>
    <td></td>
</tr>
<tr>
    <td>click</td>
    <td>id=CAP_523</td>
    <td></td>
</tr>
<tr>
    <td>click</td>
    <td>link=Done</td>
    <td></td>
</tr>
<tr>
    <td>click</td>
    <td>css=#CapContent_Tab &gt; a.deliveryModeTabLink.messageChannelChoicesTabLink</td>
    <td></td>
</tr>

</tbody></table>
</body>
</html>

作为旁注,我在IRB中运行命令,并在访问安全链接时获得以下操作,并且操作失败并出现以下错误:

irb(main):055:0> safeButton = browser.link :id => 'safeModeLink'
=> #<Watir::Anchor:0x6a5383a0 located=false selector={:id=>"safeModeLink", :tag_
name=>"a"}>
irb(main):056:0> safeButton.click
Selenium::WebDriver::Error::UnknownError: [JavaScript Error: "a is null" {file:
"file:///C:/Users/TSTURG~1/AppData/Local/Temp/webdriver-profile20141003-6084-rb5
gxf/extensions/fxdriver@googlecode.com/components/command-processor.js" line: 88
77}]'[JavaScript Error: "a is null" {file: "file:///C:/Users/TSTURG~1/AppData/Lo
cal/Temp/webdriver-profile20141003-6084-rb5gxf/extensions/fxdriver@googlecode.co
m/components/command-processor.js" line: 8877}]' when calling method: [nsIComman
dProcessor::execute]
        from C:/Ruby193/lib/ruby/gems/1.9.1/gems/selenium-webdriver-2.43.0/lib/s
elenium/webdriver/remote/response.rb:52:in `assert_ok'
        from C:/Ruby193/lib/ruby/gems/1.9.1/gems/selenium-webdriver-2.43.0/lib/s
elenium/webdriver/remote/response.rb:15:in `initialize'
        from C:/Ruby193/lib/ruby/gems/1.9.1/gems/selenium-webdriver-2.43.0/lib/s
elenium/webdriver/remote/http/common.rb:59:in `new'
        from C:/Ruby193/lib/ruby/gems/1.9.1/gems/selenium-webdriver-2.43.0/lib/s
elenium/webdriver/remote/http/common.rb:59:in `create_response'
        from C:/Ruby193/lib/ruby/gems/1.9.1/gems/selenium-webdriver-2.43.0/lib/s
elenium/webdriver/remote/http/default.rb:66:in `request'
        from C:/Ruby193/lib/ruby/gems/1.9.1/gems/selenium-webdriver-2.43.0/lib/s
elenium/webdriver/remote/http/common.rb:40:in `call'
        from C:/Ruby193/lib/ruby/gems/1.9.1/gems/selenium-webdriver-2.43.0/lib/s
elenium/webdriver/remote/bridge.rb:638:in `raw_execute'
        from C:/Ruby193/lib/ruby/gems/1.9.1/gems/selenium-webdriver-2.43.0/lib/s
elenium/webdriver/remote/bridge.rb:616:in `execute'
        from C:/Ruby193/lib/ruby/gems/1.9.1/gems/selenium-webdriver-2.43.0/lib/s
elenium/webdriver/remote/bridge.rb:198:in `switchToDefaultContent'
        from C:/Ruby193/lib/ruby/gems/1.9.1/gems/selenium-webdriver-2.43.0/lib/s
elenium/webdriver/common/target_locator.rb:76:in `default_content'
        from C:/Ruby193/lib/ruby/gems/1.9.1/gems/watir-webdriver-0.6.11/lib/wati
r-webdriver/browser.rb:367:in `assert_exists'
        from C:/Ruby193/lib/ruby/gems/1.9.1/gems/watir-webdriver-0.6.11/lib/wati
r-webdriver/elements/element.rb:532:in `locate'
        from C:/Ruby193/lib/ruby/gems/1.9.1/gems/watir-webdriver-0.6.11/lib/wati
r-webdriver/elements/element.rb:510:in `assert_exists'
        from C:/Ruby193/lib/ruby/gems/1.9.1/gems/watir-webdriver-0.6.11/lib/wati
r-webdriver/elements/element.rb:119:in `click'
        from (irb):56
        from C:/Ruby193/bin/irb:12:in `<main>'

0 个答案:

没有答案