0

I have two buttons:

BUTTON1:

<button id="pt1:r1:0:pt1:refresh" class="x28x x7j p_AFTextOnly" onclick="return false;">
REFRESH
<span id="pt1:r1:0:pt1:j_id__ctru171pc2" class="x283 x18k"></span>
</button>

BUTTON2:

<button id="pt1:r1:0:pt1:refreshFileAttachments" class="x28x x7j p_AFTextOnly" onclick="return false;">
REFRESH
<span id="pt1:r1:0:pt1:j_id__ctru370pc2" class="x283 x18k"></span>
</button>

So to distinguish them I use

BUTTON1: //button[contains(@id,'refresh') and not contains(@id,'refreshFile')]

BUTTON2: //button[contains(@id,'refreshFileAttachments')]

One page should NOT have these buttons. I verified that. Another page should have these buttons. When I tried verifying, it could not find BUTTON1. I verified using inspect that both buttons and there, and viewing them on the screen they are both visible.

So what did I do wrong? Can you not use not contains? An alternative. I know there is a starts-with(@id,...) but there is no ends-with(@id,...).

Any thoughts?

alecxe
  • 462,703
  • 120
  • 1,088
  • 1,195
user3257891
  • 275
  • 1
  • 4
  • 13
  • Why not use css? it is faster and not browser dependent. – SkorpEN Feb 03 '15 at 15:01
  • I thought about it but I never figured out or understood how to do it. And Selenium has @FindBy( xpath = ....) and not sure if you can use css that way? – user3257891 Feb 03 '15 at 15:07
  • Could you also share how are you finding the buttons (the code)? Are you sure the problem is inside the xpath expression and not in smth else - e.g. the button is not yet appeared while you are trying to find it? Thanks. – alecxe Feb 03 '15 at 15:10
  • Yes, in Chrome you can right click inspect on an element and it will show the HTML. Apparently, the way our web center works it makes long id's like ptr1:div1:sec1:ptr1_1:refreshFiles. The first parts of the buttons could change depending on the if they add new sections, but the last part is supposed to remain constant usually. I have to find 4 buttons. This is the third. An assert is done when something is not found (and should be) so I don't know if it finds the fourth button, but it found the first two. What I will do is comment out this check and see if it finds all the others. – user3257891 Feb 03 '15 at 15:34
  • @user3257891 ok, you are saying that there are more buttons found? Can you share the HTML code of the container containing all the buttons and the (I assume) java code you have so far? Thanks. – alecxe Feb 03 '15 at 15:38
  • Does it say xpath not valid or element not found? What if you try extra brackets after NOT `//button[contains(@id,'refresh') and not (contains(@id,'refreshFile'))]`. Without these extrabrackets Firebug highlights xpath as not valid. – olyv Feb 03 '15 at 15:38
  • I will try these. Unfortunately, system is down right now. When it is back up I will. – user3257891 Feb 03 '15 at 15:41
  • Do you mean //button[contains(@id,'refresh') and [not (contains(@id,'refreshFile'))]] ? 3257891 yes other buttons are found. I am going to try commenting this one out. I may just not understand how to specify xpath. – user3257891 Feb 03 '15 at 15:42
  • Sorry, I meant parentheses `//button[contains(@id,'refresh') and not (contains(@id,'refreshFile'))]` – olyv Feb 03 '15 at 15:57
  • Hi. Yeah this seems to work. Thanks for help: `@FindBy(xpath = "//button[contains(@id,'refresh') and not (contains(@id,'refreshFile'))]")` – user3257891 Feb 03 '15 at 16:42
  • Sure U could use @FindBy( css = ... – SkorpEN Feb 04 '15 at 12:08

0 Answers0