XPath is broken when changes are made
This is the current situation: There are several files and folders in a
specific location.
once you hover over a file or a folder, an icon appears then you can click
on that icon and a menu will appear too,
and from that menu a user can select any action(rename, move,etc). The
problem is that
the XPath which is provided by FirePath is broken whenever a new
file/folder is created/added in the location.
This is the initial line of code which works fine until the XPath is broken:
webDriver.findElement(By.xpath("//*[@id='main_files_view']/ol/li[6]/ul/li[4]")).click();
Whenever a new item is added in the location, the index with value "6" can
change to "7" (new position of the file) and the XPath generated is now
slightly different:
webDriver.findElement(By.xpath("//*[@id='main_files_view']/ol/li[7]/ul/li[4]")).click();
How can I change that XPath and makes it robust so that no matter the
number of items added/removed, the XPath will not break?
Bellow is the section of the HTML which is related to the XPath provided
by FirePath.
When the XPath is provided, the last class is also highlighted.
<li class="storage_item document file_object even ui-draggable"
data-thumb-translation="Translated" data-possible-actions="Rename Delete
Share Move View" data-file-size="0 bytes" data-item-type="file"
data-display-name="solids_A" data-name="solids_A.raas"
data-id="bd48453c752043d98afb237b86ee88a3">
<a class="file_name"
href="#/Item/Details?id=bd48453c752043d98afb237b86ee88a3&itemtype=File&tab=Default">
<img class="file_list_icon" width="16" height="16"
src="https://api-staging.autodesk.com/content/gateway/2013.1.307595.626/z/Content/images/fileIcons/small/raas.png"/>
<div class="name_container">
<ul class="tools">
<li class="preview_trigger"/>
<li class="comment_balloon none has_tooltip"
data-tooltip-contents="#comment_balloon_tooltip"
data-comments="0">
<li class="categorize action has_tooltip" data-tooltip="Categories"/>
<li class="document_tools has_tooltip" data-tooltip="Actions"/>
</ul>
</li>
I am using Selenium 2.0, on Eclipse IDE. Your help will be very appreciated.
No comments:
Post a Comment