Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

set(Keys.ESCAPE) or .press_escape is not working when im trying to interact with not interactable element on webpage #462

Open
vrapsa opened this issue Nov 4, 2022 · 1 comment

Comments

@vrapsa
Copy link

vrapsa commented Nov 4, 2022

Hey!
So my problem is that i cant use .press_escape or set(Keys.ESCAPE) in some cases.

The code is below:
browser.open("https://www.dns-shop.ru/")
s(by.xpath("//a[text()='ТВ и мультимедиа']")).click()
s(by.xpath("//a[@Class='subcategory__item ui-link ui-link_blue']")).click()
s(by.xpath("//a[@Class='subcategory__item ui-link ui-link_blue']")).click()
ss(by.xpath("//div[@Class='catalog-product__stat']//label[@Class='ui-checkbox']")).element(0).click()

/Problem code below/
s(by.xpath("//button[@Class='button-ui button-ui_brand compare-login-modal__login-btn']")).press_escape()
or
s(by.xpath("//button[@Class='button-ui button-ui_brand compare-login-modal__login-btn']")).set(Keys.ESCAPE)

/Working code/
s(by.xpath("//button[@Class='button-ui button-ui_brand compare-login-modal__login-btn']")).send_keys(Keys.ESCAPE)
or
s(by.xpath("//button[@Class='button-ui button-ui_brand compare-login-modal__login-btn']")).type(Keys.ESCAPE)

@yashaka
Copy link
Owner

yashaka commented Dec 6, 2022

Hey, first of all, please, report an issue appropriately. The good report should contain error message at least and the version of selene you use.

Secondly...

there might be a good reason why set(Keys.ESCAPE) or set_value(Keys.ESCAPE) does not work. set is based on set_value. And set_value is based on clear + send_keys. Some fields have a special behavior for events triggered on clear. That's why you may get not what you expect. Then you just should not use set_value, but use send_keys or type instead.

It's weird though that send_keys(Keys.ESCAPE) works but press_escape() does not, because they should be completely the same under the hood. But to investigate this - I need to see your error message

P.S.
Also, please, since you use selene, learn how to use it more efficientely.

The code

browser.open("https://www.dns-shop.ru/")
s(by.xpath("//a[text()='ТВ и мультимедиа']")).click()
s(by.xpath("//a[@Class='subcategory__item ui-link ui-link_blue']")).click()
s(by.xpath("//a[@Class='subcategory__item ui-link ui-link_blue']")).click()
ss(by.xpath("//div[@Class='catalog-product__stat']//label[@Class='ui-checkbox']")).element(0).click()

can be simplified to

browser.open("https://www.dns-shop.ru/")
s("//a[text()='ТВ и мультимедиа']").click()
s("//a[@Class='subcategory__item ui-link ui-link_blue']").click()
s("//a[@Class='subcategory__item ui-link ui-link_blue']").click()
ss("//div[@Class='catalog-product__stat']//label[@Class='ui-checkbox']").first.click()

you also can consider refactoring selectors to achive even more readable code

browser.open('https://www.dns-shop.ru/')
s(by.text('ТВ и мультимедиа')).click()
s('.subcategory__item.ui-link.ui-link_blue').click()
s('.subcategory__item.ui-link.ui-link_blue').click()
ss('.catalog-product__stat .ui-checkbox').element(0).click()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants