-1

I need help locating a dynamic element on a web page.

Even though the id changes each time, it always starts with "ember10", and has the word "btn-primary" in the class, and no other element has both of those characteristics.

I tried using,

driver.findElements(By.XPATH,(//*[contains(@id, ‘ember10’)and contains(@class,'btn-primary')

But I keep getting Invalid Snytax errors when I run. Anyone know how I would go about locating this dynamic element?

itronic1990
  • 1,231
  • 2
  • 4
  • 18

2 Answers2

0

xpath is a string. Wrap all of that up in quotes.

edit: based on @JD2775's comment, I've removed the remainder of this answer.

  • Agreed on the first part, definitely NOT on the 2nd part. `And` conditions exist in Xpath and should be used for this purpose https://stackoverflow.com/questions/10247978/xpath-with-multiple-conditions – JD2775 May 18 '21 at 22:19
  • 1
    Trusting @JD2775 here, since I never use conditionals in xpaths. I'll edit. – Simulacra at Tanagra May 18 '21 at 22:35
  • Ok I used the code below and got no errors, it's a mixture of what you both wrote. Is there a way to test if it was correctly located? I don't want to add .click() since that will place an order. I've just been coding for 3 days, still have a lot to learn. POButton = driver.find_element(By.XPATH,"//*[contains(@id, 'ember10')] and contains(@class, 'btn-primary')]") – Valstorm Warsong May 18 '21 at 22:38
  • test your xpath in chrome browser developer console. $x("your xpath") should find your webelement – itronic1990 May 18 '21 at 23:20
0

Try this xpath. You are missing double quotes and paranthesis in your xpath. Also if you are trying to find one element, it should be driver.findElement and not findElements

driver.find_element(By.XPATH,("//*[contains(@id, ‘ember10’) and contains(@class,'btn-primary')]")
itronic1990
  • 1,231
  • 2
  • 4
  • 18