Modelizer / Laravel-Selenium

Selenium Testing for Laravel 5
MIT License
108 stars 33 forks source link

click and press methods #13

Closed gcw07 closed 8 years ago

gcw07 commented 8 years ago

OK, I've been playing around with both of these methods and how it searches through xpath. I think they should be changed from this:

$this->findElement($text, "//button[contains(text(), '{$text}')]")->click();

to

$this->findElement($text, "//button[contains(., '{$text}')]")->click();

Basically the problem is with the way it is, is that text() only will find information if that is the only thing within the element. So for instance, if you have an icon within a button like:

<button class="btn btn-primary">
   <i class="fa fa-trash"></i> Delete
</button>

It will not find the text "Delete". It only finds it if it is just

<button class="btn btn-primary">
   Delete
</button>

Same thing for the click method. Change it from this:

$this->findElement($textOrId, "//a[contains(text(), '{$textOrId}')]");

to

$this->findElement($textOrId, "//a[contains(., '{$textOrId}')]");

I'm not sure there are any downsides to the change, but I'm not an xpath expert so can't be 100% sure of that. But buttons and links often have other elements within and the current implementation with text() does not seem to work with that.

Modelizer commented 8 years ago

Yes, agreed I think you are right and found similar question.

Thanks again 👍

Modelizer commented 8 years ago

Fixed.