set(Keys.ESCAPE) or .press_escape is not working when im trying to interact with not interactable element on webpage
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)
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()