1

This is my button link:

<a class="button" href="#" onclick="ajaxtoelement('include/system.php?mode=begin&amp;location='+getSelectedValue('location')+'&amp;terminallane='+getSelectedValue('terminallane')+'','keyboard')</a>"

And I have tried doing

driver.findElement(By.xpath("//a[@class='ajaxtoelement('include/system.php?mode=begin&amp;location='+getSelectedValue('location')+'&amp;terminallane='+getSelectedValue('terminallane')]"));

Why can't selenium still find the button I'm specifying?

3
  • 2
    ajaxtoelement('include/system.... is not the class of the element Commented Jul 31, 2015 at 6:11
  • 1
    can you share the error log of your IDE console ? Commented Jul 31, 2015 at 6:12
  • Besides what Fran said, you've tried to nest single quotes within single quotes; XPath can't parse that. Commented Jul 31, 2015 at 7:34

3 Answers 3

2

It should be accessed via onclick and not class one simple way is,

driver.findElement(By.xpath("//a[contains(@onclick, 'onClickValue')]");
Sign up to request clarification or add additional context in comments.

2 Comments

Looks like you have missed to close ']'
@Vicky yes. fixed!! Thanks.
1

I don't know your HTML structure, but

How many buttons do you have?

If you only have one button you don't need xpath, use the simpler way:

driver.findElement(By.className("button"));

If there are several more buttons, but the button you described is the only one that contains for example the word "terminallane":

driver.findElement(By.xpath("//a[@class = 'button' and contains(@onclick, 'terminallane')]"));

Comments

0

Try with the below xpath::

//a[@href='#']

else

//a[contains(@onclick, 'ajaxtoelement('include/system.php?mode=begin&amp;location='+getSelectedValue('location')+'&amp;terminallane='+getSelectedValue('terminallane')+'','keyboard')')]

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.