Reputation: 410
I am trying to find an element using css selector and href with a partail link but I keep getting an invalid selector error
What am I doing wrong?
<a href="javascript:shipdateCheck('updateShipDate',#####,'false');" class="actionlink2">
<img src="images/save-16x16.bmp" width="12px" height="12px" alt="Update
Ship Date For ######" border="0">
</a>
the ##### is a number as a string that is randomly generated.
date_save = driver.find_element_by_css_selector('a[href*="javascript:shipdateCheck("updateShipDate","]')
Upvotes: 0
Views: 449
Reputation: 3790
You have a typo of having a *
in href. Also if you do not use the actual equals value then you can use contains. If you have double quotes inside double quotes you need to escape them with \".
date_save = driver.find_element_by_css_selector('a[contains(@href, "javascript:shipdateCheck(\"updateShipDate\",")]')
Upvotes: 1
Reputation: 33384
To click on anchor tag induce WebDriverWait()
and element_to_be_clickable()
and following css selector.
WebDriverWait(driver,10).until(EC.element_to_be_clickable((By.CSS_SELECTOR,"a[href*=\"javascript:shipdateCheck('updateShipDate'\"]"))).click()
You need to import following libraries.
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By
Upvotes: 0