how can i href print?. how can i print link(aaaaa.pdf) with python selenium? Thank you very much to everyone who replied.
<div >
<a href="aaaaa.pdf"></a>
</div>
CodePudding user response:
You can do like this:
print(driver.find_element_by_css_selector(".xxxx a").get_attribute('href'))
CodePudding user response:
div.xxxx a
first, check if this CSS_SELECTOR
is representing the desired element.
Steps to check:
Press F12 in Chrome
-> go to element
section -> do a CTRL F
-> then paste the css
and see, if your desired element
is getting highlighted with 1/1
matching node.
If yes, then use explicit waits:
wait = WebDriverWait(driver, 20)
print(wait.until(EC.element_to_be_clickable((By.CSS_SELECTOR, "div.xxxx a"))).get_attribute('href'))
Imports:
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
CodePudding user response:
Try the below:
pName = driver.find_element_by_css_selector(".xxxx").text
print(pName)
or
pName = driver.find_element_by_css_selector(".xxxx").get_attribute("href")
print(pName)