0

I need to click on the "Visualizar cruzeiros" button on this site: https://www.disneytravelcenter.com/MIN-000000000031063/sites++disney-cruise-line++cruises-destinations++alaska++view-sailings++view-sailings/

Unfortunately, I cannot do it by simply using:

visualizar = driver.find_element_by_css_selector('#jb-card-txt-blk-redirect-link-zone-' + zona + 'night-' + str(c)+ '.redirectLink') visualizar.click()

Or using:

visualizar= driver.find_element_by_class_name('redirectLink')
visualizar.click()

Or using:

visualizar= driver.find_element_by_xpath('//*[@id="jb-card-txt-blk-redirect-link-zone-' + zona + 'night-' + str(c) +'"]')
visualizar.click()

How am I supposed to click on this button then?

OBS: The "zona" and str(c) are loop variables, but they don't change the result of the code, actually.

2 Answers 2

1

Have you tried using xpath //a[contains(text(),'Visualizar cruzeiros')? This should return more than one element, you need to get the second one.
Try to write a test case with selenium IDE, it may give you a hint how to access the element.

Sign up to request clarification or add additional context in comments.

2 Comments

Trying your solution gave me this as return: Message: invalid selector: Unable to locate an element with the xpath expression //a[contains(text(),'Visualizar cruzeiros') because of the following error: SyntaxError: Failed to execute 'evaluate' on 'Document': The string '//a[contains(text(),'Visualizar cruzeiros')' is not a valid XPath expression.
My line of code: visualizar = driver.find_elements_by_xpath("//a[contains(text(),'Visualizar cruzeiros')")[0] visualizar.click()
0

Found out the answer to my problem:

button = driver.find_elements_by_xpath('//*[@id="jb-card-txt-blk-redirect-link-zone-' + zona + 'night-' + str(c) + '"]')[2]
button.click()

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.