简体   繁体   中英

Dynamic Web Elements Help - Selenium Python

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?

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.

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')]")

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM