I have an "onclick" element in a webpage whose HTML reads as follows:
I want to search this element using the string "fastener" or "Fastener" using Python + Selenium. The number "3625" will change depending on previous inputs, and hence cannot be searched for.
I tried the following, but in vain:
br.find_element_by_css_selector("a[@onlick*='fastener']").click()
Please suggest ways to do this. Thank you!
P.S.: I am using Python 2.7, with Chrome WebDriver and Chrome v62.
解决方案
To search the element with text as Fastener you can use either of the following options :
Through Fastener :
br.find_element_by_link_text("Fastener").click()
Using onclick through fastener (xpath):
br.find_element_by_xpath("//a[contains(@onclick,'fastener')]").click()
Using onclick through fastener (css_selector):
br.find_element_by_css_selector("a[onclick^='fastener']").click()