原文链接: http://stackoverflow.com/questions/5948881/locating-a-li-element-using-text-using-watir-webdriver
Question
I am trying to locate and click on a jQuery menu element, the menu is defined as multiple UL elements containing a number of LI elements.
Using Firefox 3.6.17 on Mac 10.5, in standard WATIR I've used;
browser.li(:text,"Options...").click
or
browser.div(:id,"Attributes-menu").li(:text,"Copy").click
to click on the menu item but using watir-webdriver (0.2.3) it is reporting the LI element cannot be found. Although I can find the containing DIV and an instance of LI by using :class.
I've attached an example of a menu HTML below, can anyone suggest a reliable method of locating the LI item?
<div class="ws-menu-container ws-context-menu ws-context-menu-hidden" style="top: 16px; left: 214px; " id="Attributes-menu">
<ul class="ws-context-menu"><li class="ws-context-menu-disable"> Copy </li></ul>
<hr class="ws-context-menu-separator">
<ul class="ws-context-menu">
<li class="ws-context-menu-disable"> Add... </li>
<li class="ws-context-menu-disable"> Remove... </li></ul>
<hr class="ws-context-menu-separator">
<ul class="ws-context-menu">
<li class="ws-context-menu-disable"> Clear Translation Flag </li>
<li class="ws-context-menu-disable"> Copy from Master Language... </li>
<li class="ws-context-menu-disable"> Push to Child Languages... </li></ul>
<hr class="ws-context-menu-separator">
<ul class="ws-context-menu">
<li class="ws-context-menu"> Options... </li></ul>
<hr class="ws-context-menu-separator">
<ul class="ws-context-menu">
<li class="ws-context-menu"> Refresh </li></ul>
<hr class="ws-context-menu-separator">
<ul class="ws-context-menu">
<li class="ws-context-menu"> Help </li></ul></div>
Answers
A1:
This worked for me:
browser.div(:id => "Attributes-menu").li(:text => /Copy/).click
A2:
The reason it's not found is the nbsp;'s. In addition to Željko's regexp solution, you should be able to do this by adding the Unicode bytes for a non-breaking space to the string you're looking for, e.g:
browser.li(:text => "\xc2\xa0\xc2\xa0\xc2\xa0Options...\xc2\xa0\xc2\xa0\xc2\xa0")
A3:
To do Zeljko's solution but using a string variable you need to create a new instance of the regular expression class from your string variable
searchtext = Regexp.new(mystringvariable)
browser.div(:id => "Attributes-menu").li(:text => searchtext).click
for more info see the Rdoc for the Ruby Regexp class
发表评论
-
Get values from a select list using xpath [closed]
2012-04-04 16:50 0http://stackoverflow.com/que ... -
How do I build Watir tests for websites?
2012-04-04 16:14 0http://stackoverflow.com/que ... -
“TypeError: can't convert String into Integer” when trying to CTRL+click or SHIF
2012-04-04 15:33 0http://stackoverflow.com/que ... -
Using Watir, how can I select a radio control using both name and value?
2012-04-04 15:23 0q http://stackoverflow.com/q ... -
Selecting multiple options in select list with shift
2012-04-04 15:19 0Q http://stackoverflow.com/ques ... -
Drag-and-Drop in Watir
2012-04-04 15:15 0http://www.cheezyworld.com/2010 ... -
How to test onclick in this object without id
2012-04-04 15:13 0http://stackoverflow.com/que ... -
Browser Certificates
2012-04-04 15:01 0http://watirwebdriver.com/b ... -
selected_options returns blank from iframe
2012-04-04 14:48 0link http://stackoverflow.com/q ... -
How to handle tinyMCE when automating with watir-webdriver?
2012-04-04 14:28 0I'm evaluating Watir-webdr ... -
Browser url not returning new url
2012-04-01 17:55 0Qhttp://stackoverflow.com/quest ... -
Can not drive Opera with watir-webdriver on Windows XP
2012-04-01 17:53 0Qhttp://stackoverflow.com/quest ... -
why must I sleep or wait using watir-webdriver and firefox?
2012-04-01 17:50 0Qhttp://stackoverflow.com/quest ... -
Firefox 4 with watir webdriver: Need help using helperApps.neverAsk to save CSV
2012-04-01 17:39 0Q http://stackoverflow.com/q ... -
Watir Webdriver counting number of items in a UL list
2012-04-01 17:22 0Q http://stackoverflow.co ... -
finding the direct child of a tag in watir
2012-04-01 17:13 0Qhttp://stackoverflow.com/quest ... -
How to determine browser type (IE, FF, Chrome, etc.)
2012-04-01 16:59 0Q http://stackoverflow.com/que ... -
Wait methods for watir-webdriver unsuccessful with JS/AJAX and new page load (Er
2012-04-01 16:19 0http://stackoverflow.com/questi ... -
How to send text to a CKEditor WYSIWYG editor box using Watir-WebDriver
2012-04-01 16:14 0Q http://stackoverflow.com/ques ... -
How can I get Browser.text.include? to be case insensitive?
2012-04-01 15:57 0Q:http://stackoverflow.com/ques ...
相关推荐
Solve your Selenium WebDriver problems with this quick guide to automated testing of web applications with Selenium WebDriver in C#. Selenium WebDriver Recipes in C#, Second Edition contains hundreds ...
Selenium.WebDriver.4.0.0-alpha02.nupkg,Selenium.WebDriver 4.0,Selenium is a set of different software tools each with a different approach to supporting browser automation. These tools are highly ...
Adobe Boxes: Locating Object Proposals Using Object Adobes
Instaling and Locating Power Pivot Before You Start Using Power Pivot Gettina Your Data into Power Pivot Linking the Data Sets Together Creating a pivot Table from the Creating a Pivot Table from the ...
ssh 登录尝试监控这个 repo 基于这篇名为创建文章,并在设置环境方面有更多的细节。 我将使用 kubernetes 来运行以下部分: infludb:时间序列数据库grafana:用于在地图上可视化登录尝试登录收集器:rsyslogd 调用...
by locating 30 human parts detected by a well trained human detector. Then, founded on part features, we propose a two-step calculation to obtain more reliable one-to-many similarities between the ...
1.Fixed: a bug in bookmark locating. 2.Fixed: a bug in the rtf-to-text parser, which applies to search, word count, index, etc. 3.Fixed: a bug in the toolbar, size corruption on the WM_SETTINGCHANGE ...
Locating a pattern within a string 58 Returning a range of characters from a string 59 Creating a string of repeated characters 60 Replacing ranges of characters contained within a string 60 Creating ...
基于ASM算法的特征点定位论文,内容翔实
Big Data Analytics Using Splunk is a hands-on book showing how to process and derive business value from big data in real time. Examples in the book draw from social media sources such as Twitter ...
Using Special Fonts for Text 310 Displaying Images 318 Chapter 8: Event Handling 323 Basics of Event Handling 324 Actions 342 Mouse Events 349 The AWT Event Hierarchy 357 Chapter 9: User ...
Locating a Device Using Global Positioning System and Network/WiFi Technology AIR and Android Reverse Geocoding Maps EXIF Data and the Map Object The speed Property Conclusion Chapter 11 : Microphone...
爱立信Locating算法详解爱立信Locating算法详解爱立信Locating算法详解
The effectiveness of a geographical decision support tool (Dragnet) for locating the base of serial offenders was compared across 570 models comprised of a range of negative exponential functions, ...
## RFID课程设计基于射频识别技术的大楼人员定位系统后台-WEB ###简介 硬件采用RFID打卡,阅读器ARM将数据通过Wi-Fi发送到转发的电脑,再把数据通过网络转发到服务器,服务器对数据存储表操作。...
Locating a Device Using Global Positioning System and Network/WiFi Technology AIR and Android Reverse Geocoding Maps EXIF Data and the Map Object The speed Property Conclusion Chapter 11 : Microphone...
Locating a Device Using Global Positioning System and Network/WiFi Technology AIR and Android Reverse Geocoding Maps EXIF Data and the Map Object The speed Property Conclusion Chapter 11 : Microphone...
Locating a Device Using Global Positioning System and Network/WiFi Technology AIR and Android Reverse Geocoding Maps EXIF Data and the Map Object The speed Property Conclusion Chapter 11 : Microphone...
that are not yet using glibc 6), test_strftime fails due to a non-standard implementation of strftime() in the C library. Please ignore this, or upgrade to glibc version 6. By default, tests are ...