无法使用selenium键入IE8中显示的contentedable div

时间:2011-06-04 11:55:03

标签: selenium selenium-rc

我在IE8浏览器中使用selenium 1自动化Sharepoint站点时遇到了以下问题。我无法输入标签(Sharepoint人员选择器字段) 以下是html代码:

 <td sizcache="10" sizset="0">    
       <div tabIndex="0"
                title="People Picker"
                class="ms-inputuserfield"
                id="ctl00_ctl00_pePeopleEditor_upLevelDiv"
                style="overflow-x: hidden; overflow-y: auto; background-color:window; width: 100%; height: 18px; color: windowtext;"
                contentEditable="true"
                onkeydown="return onKeyDownRw(this, 'ctl00_ctl00_pePeopleEditor',3, true, event);"
                onkeyup="return onKeyUpRw('ctl00_ctl00_pePeopleEditor');"
                onclick="onClickRw(true, true);"
                onblur="updateControlValue('ctl00_ctl00_pePeopleEditor')"
                ondragstart="canEvt(event);"
                oncopy="docopy();"
                onpaste="dopaste();"
                onfocusin="this._fFocus=1;saveOldEntities('ctl00_ctl00_pePeopleEditor_upLevelDiv')"
                onfocusout="this._fFocus=0;"
                name="upLevelDiv"
                AutoPostBack="0"
                onChange="updateControlValue('ctl00_ctl00_pePeopleEditor')"
       />

       <textarea
               name="ctl$ctl00$pePeopleEditor$downlevelTextBox"
               title="People Picker"
               class="ms-input" id="ctl00_ctl00_pePeopleEditor_downlevelTextBox"
               style="position: absolute; width: 100%; display: none; height:20px;"
               onkeydown="return onKeyDownRw(this, 'ctl00_ctl00_pePeopleEditor', 3,true, event);"
               onkeyup="onKeyUpRw('ctl00_ctl00_pePeopleEditor');"
               rows="1"
               cols="20"
               AutoPostBack="0"
       />
</td>

我尝试使用selenium函数将文本放入该字段,如下所示,但没有一个能够解决:

self.selenium.click(div_locator)
self.selenium.type_keys(div_locator, "string")
self.selenium.key_press(div_locator, "string")
self.selenium.key_press_native(65)
------------------------------------------------------------------------------------

self.selenium.fire_event(div_locator,"focus")
self.selenium.type_keys(div_locator, "string")
self.selenium.key_press(div_locator, "string")
self.selenium.key_press_native(65)
----------------------------------------------------------------------------------

self.selenium.click_at(div_locator,"") 
self.selenium.type_keys(div_locator, "string")
self.selenium.key_press(div_locator, "string")
self.selenium.key_press_native(65)
------------------------------------------------------------------------------------

self.selenium.click(textbox_locator)
self.selenium.type(textbox_locator, "string")
self.selenium.type_keys(textbox_locator, "string")
self.selenium.key_press(textbox_locator, "string")
self.selenium.key_press_native(65)
------------------------------------------------------------------------------------

self.selenium.fire_event(textbox_locator,"focus")
self.selenium.type(textbox_locator, "string")
self.selenium.type_keys(textbox_locator, "string")
self.selenium.key_press(textbox_locator, "string")
self.selenium.key_press_native(65
----------------------------------------------------------------------------------

self.selenium.set_cursor_position(textbox,-1)
self.selenium.key_press(textbox_locator,  "\\13")
self.selenium.key_press_native(10)
self.selenium.key_press_native(65)

另请注意,FF和IE6上的此字段没有问题

有没有人知道如何处理这个Sharepoint人员选择器字段?

阿列克

1 个答案:

答案 0 :(得分:1)

我没有找到解决问题的方法,但似乎这是硒1的限制。

根据David Burns,克服此问题的一种方法是使用Selenium 2.事实上,我可以使用Selenium 2在IE8上键入此字段。 大卫还指出了克服标签问题的方法,其中contenteditable设置为true:

  

我已经开始移动我的Internet Explorer Selenium Tests,使用WebDriver API来测试我们网站的Editor组件。这是使用Selenium 1进行自动化的最难的区域之一,因为它在div上使用contentEditable。我设法使用组件JavaScript API对其进行测试以注入HTML然后对其进行操作,然后使用API​​再次获取HTML并检查它是否正确。

总结一下,我可以:

  • 使用Webdriver
  • 切换到Selenium 2
  • 使用JavaScript API组件 注入原始HTML