0

I am attempting to click a button on this page using a headless PhantomJSDriver() and a click() command, but it hangs for about half a minute and then claims it cannot find the element. How would I properly identify the button and simulate clicking it

My code snippet:

driver.findElement(By.xpath("//input[@class='btn btn-primary btn-xs' and @type='button']"))
.click();

The error message:

[ERROR - 2015-07-22T23:01:51.589Z] WebElementLocator -
_handleLocateCommand - Element(s) NOT Found: GAVE UP. Search Stop Time: 1437606111543

The inspected element:

<td ng-show="hit.HITStatus == 'Unassigned'" class="col-sm-1">
    <a href="www.theurl.com">
        <button type="button" class="btn btn-primary btn-xs">What the button says</button>
    </a>
</td>
Dumpcats
  • 453
  • 5
  • 21

1 Answers1

-1

Look... Code

class="btn btn-primary btn-xs"

means that this element is assigned not to the class "btn btn-primary btn-xs", its means that this element is assigned to 3 different classes: "btn", "btn-primary" "btn-xs"

So this means that you cannot find this element by this xpath: "//input[@class='btn btn-primary btn-xs' and @type='button']" as there are no such class exist =) You need to change this xpath to more correctly:

".//input[@class='btn-xs' and @type='button']"

and in this case it will not find correct button(it will find, but not correct, I think). You need to build better xpath with some parent elements included....

Andrew_STOP_RU_WAR_IN_UA
  • 9,318
  • 5
  • 65
  • 101