I have some parts of value of href(ex. The href's query value) not a full value. In this case, what method is the best to select an element (for clicking, sending keys, etc) ?
I have tried with many ways but they do not work very well. Especially, after getting html source, with 're' module, I extraced the full href. And then, I used 'webdriver.find_element(By.XPATH, "//a[@href='the full href']") But It results to 'NoSuchElementError'. ( I assume that the server continuously changes some parts of href)
Anyway,, what is the best method to find and select element only with some parts of href value ? (python3.6 / selenium module / PhantomJS)
Href containing value
//a[contains(@href, 'part/of/href')]
Href that starts with value
//a[starts-with(@href, 'http://start.of.href.')]
another option - to search not by href by itself, but By.linkedText()
- possible in java with selenium, i'm not aware if possible in python
driver.findElement(By.linkedText("some linked text inside a attribute"));
Try this:
webdriver.find_element(By.XPATH, "//a[@href='" + the_full_href + "']")
This will work if the_full_href
is a variable
Href包含值
driver.find_element_by_partial_link_text('partial href text here')
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.