K
K
Kayuro2021-09-26 13:14:01
Python
Kayuro, 2021-09-26 13:14:01

Python Selenium how to click on "cancel" button in print window?

I'm writing a parser for a Ukrainian test site, and the only place where there are answers is on the page with automatic printing.
Here is the button itself:

spoiler
6150471782758923536375.png

In the html spread, its class = 'cancel-button', from which I extract this line:
driver.find_elements_by_class_name('cancel-button').click()

But after compilation, the following error is displayed:
driver.find_elements_by_class_name('cancel-button').click()
AttributeError: 'list' object has no attribute 'click'

Also, I want to draw your attention to the fact that the page opens in a new tab, is this a problem and how can it be solved?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
K
Kayuro, 2021-09-27
@Kayuro

Guys, I was able to get around this topic in an absolutely simple, it would seem, way:

test_url = 'view-source:' + testurl + '/print'
driver.get (test_url)

Thanks everyone for the help!

O
o5a, 2021-09-26
@o5a

find_elements_by_class_name returns a list of elements, so add the index of the desired element.
In this case, I assume this element is only one, so it's easier to use another function for a single element:

driver.find_element_by_class_name('cancel-button').click()

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question