0

I am trying to find elements using Selenium Webdriver in Python by partial class name. I am very new to programming and tried using advice from https://intellipaat.com/community/9218/is-it-possible-to-locate-element-by-partial-id-match-in-selenium and Selenium WebDriver Finding Element by Partial Class Name

My code is as follows:

list5=driver.find_elements_by_xpath("//[contains(@id,‘partial id’)]")

Please let me know what is wrong with this code, as it says it is not a valid XPath expression. Thank you!

Bcat13
  • 37
  • 1
  • 1
  • 4

1 Answers1

0

You are using ´ instead of ', try like this:

list5=driver.find_elements_by_xpath("//[contains(@id,'partial id')]")

And since I don't know what exactly are you looking for, you might need to add tag name (div, span, etc.) after // i.e. //div or of course //* if you want any element.

For example if you do it for the page we are currently on you could write:

//div[contains(@id,'question')]

and you would get 3 div elements which have ids: question-header, question and hot-network-questions

cheshire
  • 1,109
  • 3
  • 15
  • 37