F
F
fandorin_official2019-06-19 22:25:02
Python
fandorin_official, 2019-06-19 22:25:02

What is the correct xpath for the popup element?

Hello.
I'm trying to implement an algorithm that will click on a button that appears in a popup menu.
I.e. There is an element of the page, when you hover the mouse on which a menu pops up. And in this menu you need to press the button.
The code is next.

d.implicitly_wait(10)
menu = d.find_element_by_css_selector('a.n-t.bold')
actions = ActionChains(d)
actions.move_to_element(menu)
hidden_submenu = d.find_element_by_xpath('//span[contains(text(),"Отписаться")]')
actions.click(hidden_submenu)
actions.perform()

Execution crashes on the line:
hidden_submenu = d.find_element_by_xpath('//span[contains(text(),"Unsubscribe")]')
And I'm not entirely sure that I'm looking for this element correctly.
A piece of code for the page with this button looks like this:

  • unsubscribe

Can you please tell me how to implement this? Where can you watch it?

Answer the question

In order to leave comments, you need to log in

4 answer(s)
1
1001001, 2019-06-19
@fandorin_official

actions.move_to_element(menu).perform()
d.find_element_by_xpath('//span[contains(text(),"Отписаться")]').click()

A
Alexey, 2019-06-19
@Toximiner

1. actions.perform() must be raised higher, because when searching for hidden_submenu , the mouse cursor has not yet hovered over menu .
2. Also, most likely, when you hover the mouse over menu , hidden_submenu appears with a delay and you need to look towards waiting https://selenium-python.readthedocs.io/waits.html

S
Shemil, 2017-08-11
@emin313

Via pseudo-element before and border jsfiddle htmlbook

C
cssfish, 2017-08-11
@cssfish

or via pseudo with transform skew
like this https://jsfiddle.net/v4uw6mvs/1/
with this approach, the height will always match, you can play with the width (and with z-index too)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question