How to disable html drawer layout in website using selenium in Java? - java

I am doing an automation for a website and I have this drawer Menu Panel that I want to open verify some elements in it then close it or hide it.
I am stuck now while trying to close/hide this drawer.
However, in the HTML I found this when it opens:
"is-visible" added to class name
Tag aria-hidden="false And when its closed/hidded"
"is-visible" removed from title
Tag aria-hidden = true
Here is the code for login and then open Menu and check Logout is displayed
login.SuccessfulLogin(testdata);
login.clickLink(By.xpath(testdata.getParam("MenuLocator")));
login.WaitForElementVisibilty(By.xpath(testdata.getParam("loginLocator")));
login.compareValue(testcase, "", expectedResultMap.get("MenuLoginTxt"),
driver.findElement(By.xpath(testData.getParam("loginLocator"))).getText());
// here should enter the code to close the menu!
log.info("User Logged in Successfully");
See screenshot
(Menu opened on the Left-side & HTML code highlighted on Right-side)

Website you are checking is accessible from network so i checked how it works. You just need to click outside of menu area. Correct element is div.mdl-layout__obfuscator.
Using java you can do this like this:
driver.findElement(By.cssSelector(".mdl-layout__obfuscator")).click();
Note: there is only one element with this class name on this page so this is sufficient. You can use any other selector type, not necessarily css selector.

Related

Is it possible to fetch the title of a web page using selenium after clicking the print button?

I need to validate the title of a web page which is changing after clicking the print button. But after clicking the button the page title is changing and also it is opening the print preview window which is out of scope for selenium. Is there any way to get the title of that page?
I have tried driver.getTitle() but that is not working in the print preview page.
Instead of using getTitle(), try the below:
WebElement title = driver.findElement(By.tagName("title"));
System.out.println(title.getText());

How to check if a popup window is open or not using Selenium WebDriver in Java

I'm trying to check whether the popup window I want to open is opened or not.
I have checked some question answers like
How would you check if a popup window exists using selenium webdriver?
But, nothings helped to solve the problem.
Here, first I open the login window by clicking the login button.
driver.findElement(By.xpath("//a[#id='login_btn']")).click(); // Click Login Button
I even tried getPageSource() but, it seems not working.
Any kind of help would be appreciated.
Thanks in advance. :)
If it's a native, browser alert (= a popup) you can do the following:
try{
driver.switchTo().alert();
// If it reaches here, it found a popup
} catch(NoALertPresentException e){}
What it looks like you're actually dealing with is an iframe which you can do the following after getting the attribute value of the "iframe" attribute:
driver.switchTo.frame("ValueOfIframe");
// Treat as normal webpage. Now in iframe scope
driver.switchTo.defaultContent(); // To return back to normal page scope
String mwh=driver.getWindowHandle();
Now try to open the popup window by performing some action:
driver.findElement(By.xpath("")).click();
Set s=driver.getWindowHandles(); //this method will gives you the handles of all opened windows
Iterator ite=s.iterator();
while(ite.hasNext())
{
String popupHandle=ite.next().toString();
if(!popupHandle.contains(mwh))
{
driver.switchTo().window(popupHandle);
/**/here you can perform operation in pop-up window**
//After finished your operation in pop-up just select the main window again
driver.switchTo().window(mwh);
}
}

How to manage pop-up using Selenium Web Driver in github

I'm having troubles with managing of the pop-up in the github.
Test case which I'd like to automate is:
1. Go to https://github.com/YOUR_USER/YOUR_REPO/settings
2. Click "Delete Repository" button (pop-up appears)
3. Fill in the name of your repository into the input in pop-up
4. Click "I understand the consequences, delete this repository" the button in pop-up
I don't know how to find the element in pop-up in the 3d step.
When I'm just tryin' to do this, webdriver fails to find element
driver.findElement(By.name("verify")).sendKeys(repoName);
Following locator (css selector) should work:
#facebox .input-block"
Use this locator as follows:
driver.findElement(By.cssSelector("#facebox .input-block")).sendKeys(repoName);
Another css selector that you can use is as follows:
#facebox [name=verify]
driver.findElement(By.cssSelector("#facebox [name=verify]")).sendKeys(repoName);
There are more that one input tags with the same name attribute value "verify". You need to select the second one and not the first. You can try something like this:
driver.findElements(By.name("verify"))[1].sendKeys(repoName);

To close webengage or clickdesk poup using selenium webdriver

I got a webengage or clickdesk alert popup but that is intermittent, so I can't check everytime or wait for it to load, everytime I enter a new webpage because that would make my test case run very slow. Is there any workaround for it ( may be blocking it).
For WebEngage, all you got to do is call the respective clear() methods for the products being used on the site (to get rid of the corresponding UI components), as underneath:
webengage.feedback.clear();
webengage.notification.clear();
webengage.survey.clear();
However, this would only work when WebEngage has loaded on the page. If you'd like to completely disable loading of WebEngage products, insert this code in head tag of the page you are testing:
var window._weq = {};
_weq['webengage.defaultRender'] = false;
You can do a lot more cool stuff like the above using our JavaScript API: http://docs.webengage.com/api/js-api-v-4.0.html
Avlesh | CEO, WebEngage
If you are using ClickDesk on your website and would like to delete the Proactive rules which pop up the chat window randomly, then these can be deleted or edited to change the frequency from this link on your ClickDesk Dashboard - https://my.clickdesk.com/#proactive.
In case, you do not want the chat widget to show up at all until clicked on a text link or an image link then, you can add our Custom image link or text link code on your website, this would enable the chat widget only when clicked on it. You can find this link here - https://my.clickdesk.com/#departments/default.
If you have further questions or concerns with regards to ClickDesk, you can visit our website www.clickdesk.com and chat with one of our agents online.
Thanks
Mike Evans
ClickDesk Corporation

How to show the content of a log file in new window when we click on a link in spring mvc

My main goal: When i click the link, a new browser window should be opened and displays the content of entire log file. And the window should not have an address bar and navigation buttons (Back, Forward).
Is there any approach to do this in Spring-MVC project?
Here is what i am doing now:
When i click the link, the controller will be called with a parameter logName.
Now the controller have access to get any kind of details of the log file like content, path, etc... I am setting all these details to an object and sending back to JSP.
Here i am not sure how to open a new window and display the content of the log file in that window.
Please suggest me an approach on this!!
It would be very helpful for me if you can share me with some examples...
Spring or JSP have nothing to do with it, the only way to force user's browser to open a link in a new tab is to use client-side Javascript. window.open() allows configuring the popup to hide certain interface elements (see all options in the documentation)
Your code would look something like:
<input type="button" value="Show Log" onclick="showLog(logName)">
function showLog(logName) {
var url = "/path-to-your-controller.html?logName=" + logName;
window.open(url, "LogPage", "toolbar=no,location=no,menubar=no");
}
However, I don't think using a customised browser popup is a good solution; it's been disappearing from the web for a reason. It would be more elegant to fetch raw data using AJAX and display it in a JS popup: it wouldn't interfere with user's page navigation (you tagged the question with jQuery, you could use jQuery UI for that).
What is more, I wouldn't be surprised if window.open wasn't supported by all browsers in the same way† - something to keep in mind if you're targeting a wider audience.
† seems that Chrome ignores location=no, for instance

Categories

Resources