检查Selenium/Python中具有ID的span元素中的文本。

huangapple go评论73阅读模式
英文:

Check Span Element with ID for text in Selenium/Python

问题

driver.find_element(By.XPATH, '//span[text()="Derzeit nicht verfügbar"]')
英文:

I want to refresh a page until a certain text changes. However, both texts are permanently present several times on the page.

So I need to check a span element with an ID and a specific text at the same time.

Can someone tell me how to do this with driver.find_element(By.XPATH,)?

Thanks and greetings
Jannis

driver.find_element(By.XPATH,'//span[text()="Derzeit nicht verfügbar"]')

答案1

得分: 1

//span[@id='example' and text()='Hello World!'] should work for you here.

英文:

//span[@id='example' and text()='Hello World!'] should work for you here.

答案2

得分: 0

你的XPATH需要一个AND运算符。

这是语法:

//tag_name[@name = 'Name value' and @id = 'ID value']

因此,你可以构建你的XPATH如下所示:

//span[text()="Derzeit nicht verfügbar" and @id="enter id value here"]
英文:

You need an AND operator in your XPATH.

This is the syntax:

//tag_name[@name = 'Name value' and @id = ‘ID value’]

So you can construct your XPATH something like below:

//span[text()="Derzeit nicht verfügbar" and @id="enter id value here"]

huangapple
  • 本文由 发表于 2023年3月15日 20:48:57
  • 转载请务必保留本文链接:https://go.coder-hub.com/75744941.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定