Hello guys I am trying to find and click on a button that seems to be hidden on the webpage : https://www.thetrainline.com/book/results?origin=69b59b70a73b72302eff45627aeef377&destination=f0269e87c1084b4e752e4cd5bbf6e062&outwardDate=2020-10-23T18%3A00%3A00&outwardDateType=departAfter&journeySearchType=single&passengerDiscountCards%5B0%5D=903ab66d2652ac9cc3e75bf63f3120cd3fecbbe2&passengers%5B0%5D=1995-10-21%7C617e5009-9253-42e9-a5d9-3e78934d9607&selectedOutward=cIcpW5313Ao%3D%3A5pIf0wIdti0%3D%3AStandard&lang=fr
The following code can click on the button "1 jeune (0-25) Ajouter une carte" up right, then the "Ajouter cartes et abonnements" button, the "SNCF - Abonnements" but I cannot click on the "Abonnement TGV max" button once the list appears.
from selenium import webdriver
driver = webdriver.Chrome('/Users/macsamy/Downloads/chromedriver')
driver.get('https://www.thetrainline.com/book/results?origin=69b59b70a73b72302eff45627aeef377&destination=f0269e87c1084b4e752e4cd5bbf6e062&outwardDate=2020-10-23T18%3A00%3A00&outwardDateType=departAfter&journeySearchType=single&passengerDiscountCards%5B0%5D=903ab66d2652ac9cc3e75bf63f3120cd3fecbbe2&passengers%5B0%5D=1995-10-21%7C617e5009-9253-42e9-a5d9-3e78934d9607&selectedOutward=cIcpW5313Ao%3D%3A5pIf0wIdti0%3D%3AStandard&lang=fr')
card = driver.find_element_by_class_name('_1m8f79NaN')
card.click()
abonnement = driver.find_element_by_class_name('_bwmpdt')
abonnement.click()
tgv = driver.find_elements_by_class_name('_1ntnz22')[1]
tgv.click()
tgv_max = driver.find_element_by_class_name('_nyjqe2')
tgv_max.click()
I tried many ways such as xpath or using js command but I could not fix the problem. I am quite new in the field so I feel a bit lost. Do you have any ideas to fix this ?
For "SNCF - Abonnements" you can use
driver.find_element_by_class_name('_1ntnz22')
And for "Abonnement TGV max" you can locate by xpath with text
driver.find_element_by_xpath('//*[text()="Abonnement TGVmax"]')
Use
ActionChains
to click.Please see the following code: