I have created selenium test scripts for our web product.I need to run the same scripts on desktop and mobile browsers both. But in mobile, due to responsive design, the hamburger menu appears which consists of links but in desktop browsers we can directly click the links. So how can I handle such situations with the same script on desktop and mobile browsers both?
Asked
Active
Viewed 169 times
0
-
The links still reside in the DOM even though they are hidden via the hamburger icon, all you have to do is get the link the same way you do in your browser based script I would think, either by CssSelector, or Id, or XPath, etc. Then call `.Click()`. If you need to click the hamburger for the links to be added into the DOM, then you would get the Hamburger icon, call click on it, then search for your link to click. If you are getting the Element Not Visible exception in Selenium, you can use the `JavascriptExecutor` to click the link using straigh javascript. – Ryan Wilson Jan 07 '21 at 17:16
-
`JavascriptExecutor` - (https://stackoverflow.com/questions/11947832/how-to-click-an-element-in-selenium-webdriver-using-javascript) – Ryan Wilson Jan 07 '21 at 17:19
-
OK Ryan. So rather than clicking on hambergur menu it would be better to click the hidden links. I mean no need to write the extra code for hamburger and then click links. Right? – Prathamesh Pawar Jan 07 '21 at 17:26
-
This is one of the examples. Same applies for other examples as well right? I am not reminding of exact examples but still. – Prathamesh Pawar Jan 07 '21 at 17:28
-
The SO post I linked above is an example of using the `JavascriptExecutor` for clicking a link, this will bypass any Selenium exception like the Element Not Visible exception when using the built in click, it will just do it through straight javascript which would negate your need for worrying about the hamburger on smaller device screens, unless, as stated, the links are only added to the DOM after clicking the hamburger, but I think most likely they exist but are just hidden because of responsive design. If you want more detailed help, please post the relevant Html – Ryan Wilson Jan 07 '21 at 17:32
-
OK thanks @RyanWilson – Prathamesh Pawar Jan 07 '21 at 17:43