简体   繁体   English

动态 Web 元素帮助 - Selenium Python

[英]Dynamic Web Elements Help - Selenium Python

I need help locating a dynamic element on a web page.我需要帮助在 web 页面上定位动态元素。

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.即使 id 每次都发生变化,它总是以“ember10”开头,并且在 class 中具有“btn-primary”一词,并且没有其他元素具有这两个特征。

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.但是当我运行时,我不断收到 Invalid Snytax 错误。 Anyone know how I would go about locating this dynamic element?任何人都知道我将如何定位这个动态元素?

xpath is a string. xpath 是一个字符串。 Wrap all of that up in quotes.将所有这些都用引号括起来。

edit: based on @JD2775's comment, I've removed the remainder of this answer.编辑:根据@JD2775 的评论,我删除了这个答案的其余部分。

Try this xpath.试试这个 xpath。 You are missing double quotes and paranthesis in your xpath.您在 xpath 中缺少双引号和括号。 Also if you are trying to find one element, it should be driver.findElement and not findElements此外,如果您试图找到一个元素,它应该是 driver.findElement 而不是 findElements

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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