I am writing a script which needs to click on an element of a page, however, the CSS selector changes everyday as the element changes it\'s location.
Today it\'s cal
To find and click on the element as the element is a dynamic element you need to induce WebDriverWait for the element_to_be_clickable()
and you can use either of the following Locator Strategies:
Using CSS_SELECTOR
:
WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "#PPTAmFCTable>tbody a[href^='/FC1/ItemList'][href$='TRANSSHIPMENTS']"))).click()
Using XPATH
:
WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//*[@id='PPTAmFCTable' and starts-with(@href,'/FC1/ItemList')][contains(@href, 'TRANSSHIPMENTS')]")))
Note : You have to add the following imports :
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC