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 called:
PPTAmFCTable > tbody:nth-child(1) > tr:nth-child(11) > td:nth-child(3) > a:nth-child(1)
Yesterday it was:
PPTAmFCTable > tbody:nth-child(1) > tr:nth-child(10) > td:nth-child(3) > a:nth-child(1)
And tomorrow it might be tr:nth-child(13)
or so.
I use the following code:
def click_element_bycss(browser,css,timeout):
element_present = EC.presence_of_element_located((By.CSS_SELECTOR,css))
WebDriverWait(browser, timeout).until(element_present)
browser.find_element_by_css_selector(css).click()
and then:
click_element_bycss(browser,"#PPTAmFCTable > tbody:nth-child(1) > tr:nth-child(11) > td:nth-child(3) > a:nth-child(1)",4)
How can I write the code in a way that I click on the right element, w/o knowing the number in the second tr:nth-child() ?
Element HTML:
<a href="/FC1/ItemList;jsessionid=E6B3D538CD809FDDC3DE69EA160C956D?WorkPool=PickingNotYetPicked&ExSDRange.RangeEndMillis=1556850660000&ProcessPath=PPTAmFC&ExSDRange.RangeStartMillis=1556850599999&shipmentType=TRANSSHIPMENTS">261</a>
Thought of a loop which just runs through for i in range(1,20): tr:nth-child(i) but would expect there's something smarter.