0

I'm trying to rename a folder from:

<li class="selected rename" id="labelset-624" folderid="624" foldertype="labelset" permissionlevel="2" labelsetid="624">
  <div class="folder-insert-drop ui-droppable"></div>
  <div class="clear"></div>
  <div class="folder-item droppable hoverable empty ui-droppable">
    <div id="mlink-labelset-624" class="folder-menu-link" data-hasfullperm="true" data-subfoldertype="undefined"></div>
    <div class="expander"></div>
    <div class="folder-name labelset label-set">New Label Set</div>
    <div class="target-bar"></div>
    <div class="folder-rename">
      <input value="New Label Set" id="folder-rename-624" maxlength="100" type="text">
    </div>

with watir-webdriver using the following commands:

@b.li(:class, "selected rename").div(:class, "folder-rename").text_field.wait_until_present
@b.li(:class, "selected rename").div(:class, "folder-rename").text_field.set labelsetName
@b.li(:class, "selected rename").div(:class, "folder-rename").text_field.send_keys :return

And it gives me the following error:

Watir::Exception::UnknownObjectException: unable to locate element, using {:class=>"selected rename", :tag_name=>"li"}

When I run my test script (test-unit), I can see the value for labelsetName entered into the text field, but it quickly disappears and reverts to the default value. This causes the send_keys statement to err.

When I enter the same commands into irb, it works perfectly. I tried adding sleeps of up to 15 seconds between steps to no avail. Is there any reason the two would work differently? Any suggestions for fixing this going forward?

carlmonday
  • 251
  • 1
  • 5
  • 13
  • Watir::Exception::UnknownObjectException: unable to locate element, using {:class=>"selected rename", :tag_name=>"li"} – carlmonday Jul 03 '13 at 22:59
  • 1
    Hmmm. You should edit your question to include the minimum amount of HTML that reproduces the issue (along with the error message). Might help debug the issue. – orde Jul 03 '13 at 23:11

2 Answers2

0

Unless you have a compelling reason otherwise, try accessing the <input> tag directly using the id attribute:

b.text_field(:id => "folder-rename-624").set "foo"
b.text_field(:id => "folder-rename-624").send_keys :return

And--if there's an associated submit button--try using that instead of send_keys :return.

EDIT: Unfortunately, I can't reproduce the disappearing text issue. But I'm adding this snippet, which should handle the incrementing id attribute:

tfs = b.text_fields
b.text_field(:id => "#{tfs.last.id}").set "foo"
b.text_field(:id => "#{tfs.last.id}").send_keys :return
orde
  • 5,233
  • 6
  • 31
  • 33
  • That number increments every time a new folder is created. So the next time I run the test the id tag will be "folder-rename-625". And unfortunately, there's no submit button. – carlmonday Jul 05 '13 at 18:14
0

Turns out that because I had run the test a number of times, each time creating a new folder, that the folder I was trying to rename got pushed off screen. This is what caused the error.

carlmonday
  • 251
  • 1
  • 5
  • 13