Not able to validate a Popup Overlay in my application - selenium

I am using Selenium webdriver using Cucumber.
I have clicked a button which open up a popup box, containing few web elements within it. I need to perform few validations in this pop up box. But once the overlay popup is displayed, I am not able to validate it using isDisplayed.
In the console, it display a Error message - java.lang.NullPointerException but I am not passing any value in any variable to validate this popup box.
My script is as below:
public static void Popupbox() {
searchbox = (Application_Pagexpath.popupboxheader).isDisplayed();
try{
Thread.sleep(100);
}catch(InterruptedException e){
e.printStackTrace(); }
if(searchbox = True) {
System.out.println("Popup is displayed"); }
}
The xpaths I am using are correct and these work fine in the firebug. Can you help me understand why I am seeing the Null pointer exception error and why Selenium is not able to validate this overlay popup.
The HTML for the overlay popup is as below:
div id="_paymentHistoryPortlet_WAR_EBillingWebportlet_:paybillHtyForm:dvAdvSearchOverlay" class="ui-dialog ui-widget ui-widget-content ui-corner-all ui-shadow ebillingAdvFltrOverlay ui-draggable ui-overlay-visible" style="width: auto; height: auto; left: 227.7px; top: 0px; visibility: visible; z-index: 1001;" role="dialog" aria-labelledby="_paymentHistoryPortlet_WAR_EBillingWebportlet_:paybillHtyForm:dvAdvSearchOverlay_title" aria-hidden="false" aria-live="polite"
div class="ui-dialog-titlebar ui-widget-header ui-helper-clearfix ui-corner-top"
div class="ui-dialog-content ui-widget-content" style="height: auto;"

Related

Is there any function in selenium to input text in field which is not visible using java?

Enter text in ABSTRACT TILE filed using send keysI'm trying to input text in ABSTRACT_TITLE using send-keys in selenium.
I tried switching frames and giving input.
<div id="reTitleCenter" class="reContent" style="height: 2.91667em;" xpath="1">
<label for="reTitleContentHiddenTextarea" style="display:none;">RadEditor hidden textarea</label>
<textarea id="reTitleContentHiddenTextarea" name="ctl00$ctl00$ctl00$phDesktop$cphContent$cphContent$reTitle" rows="4" cols="20" style="display:none;"></textarea>
<iframe frameborder="0" src="javascript:'<html></html>';" id="reTitle_contentIframe" title="Rich text editor with ID reTitle" style="width: 100%; height: 100%; margin: 0px; padding: 0px;">Your browser does not support inline frames or is currently configured not to display inline frames.</iframe>
<textarea class="reTextArea reTextAreaHidden"></textarea>
</div>
the code samples I tried -
driver.switchTo().frame("reTitle");
driver.findElement(By.xpath("//div[#id='reTitleTop']/div[#class='RadEditor_Bootstrap reToolBarWrapper']")).click();
driver.findElement(By.xpath("//div[#id='reTitleTop']/div[#class='RadEditor_Bootstrap reToolBarWrapper']")).sendKeys("This is demo abstract");
OR
driver.switchTo().defaultContent();
WebElement Abstract_title = driver.findElement(By.xpath("//html//body"));
Abstract_title.sendKeys("This is abstract demo selenium");
OR
selenium.SelectFrame("xpath_of_iframe"); (Don't know how to use it)
selenium.Type("//html/body","Thank you");

Select from dropdown box - selenium

HTML:
<span class="Select-multi-value-wrapper" id="react-select-27--value">
<div class="Select-placeholder">Select</div>
<div class="Select-input" style="display: inline-block;">
<style>input#undefined::-ms-clear {display: none;}</style>
<input role="combobox" aria-expanded="false" aria-owns="" aria-haspopup="false" aria-activedescendant="react-select-27--value" value="" style="width: 5px; box-sizing: content-box;">
<div style="position: absolute; top: 0px; left: 0px; visibility: hidden; height: 0px; overflow: scroll; white-space: pre; font-size: 13px; font-family: "Open Sans", sans-serif; font-weight: 400; font-style: normal; letter-spacing: normal; text-transform: none;"></div>
</div>
</span>
Code:
Select role = new Select(driver.findElement(By.xpath("//span[#id='react-
select-17--value']/div")));
role.selectByVisibleText("Manager");
also tried:
By.xpath("//*[#id='react-select-27--value']/div[1]");
By.xpath("//*[#id='react-select-27--value']");
I am getting following error.
Unable to locate element: {"method":"xpath","selector":"//span[#id='react-select-17--value']/div"}
please help.
You should not use Select. bec it's only applicable to select tag only.
In your case you have input tag with combobox role . Please try below code
WebElement ele = driver.findElement(By.xpath("//input[#role='combobox' and #aria-activedescendant='react-select-27--value']");
ele.click();
driver.findElement(By.xpath("//*[text()='Manager')");
The dropdown you are targeting is not your conventional HTML <select> element, hence Select class won't work. Instead you should do something like this -
driver.findElement(By.xpath("//span[#class='Select-multi-value-wrapper']")).click();
No you need to locate the exact option. Normally, you cannot see all your React elements inside your inspector. If you are using Chrome browser, you can install this extension and then view your elements, locate them and click on it using Selenium through your regular locators.
As per your code, you can not use Select here because it is a bootstrap drop down so that you can use like below sample code
WebElement DropDownClick = driver.findElement("Locator Value");
DropDownClick.click();
try {
Thread.sleep(3000);
} catch (InterruptedException e) {
e.printStackTrace();
}
//List of Drop Down locator
List<WebElement> Drop_options = driver.findElements(By.xpath("//span[#class='Select-multi-value-wrapper']//div"));
for (WebElement temp: Drop_options ) {
if (temp.getText().contains("Manager") {
temp.click();
break;
} else {
System.out.println("Continue");
}

VBA code to trigger an iframe div class element

Please help me with the below IE automation scenario,
I need a vba code to click on a web page label text (Log an Issue) which has been placed inside an iframe, the sample html code is given below,
<iframe name="VF304274040_1502270092884IF_1" title="Browse Categories" id="VF304274040_1502270092884IF_1" src="javascript:"<HTML></HTML>"" frameBorder="0" scrolling="auto" style="background-color: transparent; width: 100%; height: 100%; top: 0px; left: 0px;" allowTransparency="allowtransparency" onload="F(1,304274040).ol()" arviewbordercolor="null">
<head>XXXX
<body>XXXX
<div id XXXX>
.............
<div id XXXX>
......
<div>
<div class="categoryTitleLink">
<label class="cursor bold category_title" id="cat-title IDHAA5V0GQBL2AN3HRTMFOSP0OLB90" level="0" category="true" categoryname="Log+an+Issue" descr="#IDHAA5V0GQBL2AN3HRTMFOSP0OLB90" jQuery15019202206560111384="9">
....Text - Log an Issue
</body></head>
I've tried the below vba code to parse through the iframe and it's div class inner texts and found the "Log an Issue" element, but i couldn't trigger it.
VBA code:
doc1 = IE.document.frames(1).Name
For Each div In IE.document.frames(doc1).document.getElementsByTagName("div")
class_obj = div.innerText
If class_obj = "Log an Issue" Then ' the text was found by this loop
div.parentElement.Click ' this doesn't works (nothing happening)
End If
Next div
Please help!!
Try
doc1 = IE.document.frames(1).Name
IE.document.frames(doc1).document.getElementId("cat-title IDHAA5V0GQBL2AN3HRTMFOSP0OLB90").Click
The element has an id so try using it.

WebDriver - How to locate iframe without id

I'm trying to switch to an iframe in order to locate an element, but I'm unable to locate the iframe since it has no id or name
<div id="eyein-modal" style="display: block; position: fixed; width: 100%; height: 100%; top: 0px; left: 0px; bottom: 0px; right: 0px; z-index: 90000000; background-color: rgba(0, 0, 0, 0.6); overflow: auto; opacity: 1;">
<iframe style="display: block; width:90%; height:90%; border: 0px; margin: 2.5% auto; z-index: 90000000; overflow: hidden;" scrolling="no" src="about:blank">
<html>
<head>
<body class="">
<div id="modal">
<div id="modal-header">
<div id="header-logo">
<div id="title-container" class="">
<a id="view-event" class="button" target="_blank" href="http://www.link.com">view event</a>
<div id="close-modal" class="close-dark"></div>
close-modal is the element I need eventually
Aside from providing frame name or id, you can switch to the frame by index (zero-based):
Select a frame by its (zero-based) index. That is, if a page has three
frames, the first frame would be at index "0", the second at index "1"
and the third at index "2". Once the frame has been selected, all
subsequent calls on the WebDriver interface are made to that frame.
driver.switchTo().frame(0); // assuming this is the first frame on the page
Or, you can make a WebElement instance by locating the iframe, for example, by CSS selector:
WebElement frame = driver.findElement(By.cssSelector("div#eyein-modal iframe"));
driver.switchTo().frame(frame);
See also:
How to switch between frames in Selenium WebDriver using Java
If anyone using RSelenium in R happens on this little problem, this is what I used:
webElement <- remDr$findElement(using = "css selector", "#dsq-app1")
remDr$switchToFrame(webElement)
# note: remDr is the remoteDriver instance that needs to be opened at the beginning
or
webElement <- remDr$findElement(using = "id", value = "dsq-app1")
remDr$switchToFrame(webElement)
I had this problem ... using Webdriver with Codeception. My solution was to run a javascript snippet to give the iframe a name, and then I could switch to it based on name ... details here: https://stackoverflow.com/a/48123837/1593026
As per the html of the iframe element:
<iframe style="display: block; width:90%; height:90%; border: 0px; margin: 2.5% auto; z-index: 90000000; overflow: hidden;" scrolling="no" src="about:blank">
It is pretty much evident that the <iframe> doesn't have either of the following attributes:
id
name
class
title
specific value of src attribute
In such cases to switch to the desired iframe you can refer to the preceeding(sibling) WebElement and you can use either of the following locator strategies:
Java based solutions:
Using xpath and following:
WebElement iframe = driver.findElement(By.xpath("//div[#id='eyein-modal']//following::iframe[1]"));
driver.switchTo().frame(iframe);
Using xpath and following-sibling:
WebElement iframe = driver.findElement(By.xpath("//div[#id='eyein-modal']//following-sibling::iframe[1]"));
driver.switchTo().frame(iframe);
Using cssSelector:
WebElement iframe = driver.findElement(By.cssSelector("div#eyein-modal +iframe"));
driver.switchTo().frame(iframe);
Python based solutions:
Using xpath and following:
driver.switch_to.frame(driver.find_element(By.XPATH, "//div[#id='eyein-modal']//following::iframe[1]"))
Using xpath and following-sibling:
driver.switch_to.frame(driver.find_element(By.XPATH, "//div[#id='eyein-modal']//following-sibling::iframe[1]"))
Using cssSelector:
driver.switch_to.frame(driver.find_element(By.CSS_SELECTOR, "div#eyein-modal +iframe"))
Reference
You can find a couple of relevant discussions in:
Is it possible to switch to an element in a frame without using driver.switchTo().frame(“frameName”) in Selenium Webdriver Java?
Selenium - How to locate elements on iframe

Selenium WebDriver: How to wait for iframes to load completely? Can click on iframe element text box id = “div_4_1_2_1_1-lnk”

Question : I'm testing a page with an iframe whose contents are generated dynamically by JavaScript. I've to wait for the iframe to be loaded completely to make sure that all elements I need are present.
<iframe frameborder="0" style="border: 0px none; width: 100%; height: 290px; min-width: 0px; min-height: 0px; overflow: auto;" dojoattachpoint="frame" title="Fill Quote" src=" =1&zTaskId=9309&zResetContext=true&coachDebugTrace=none>
------------------------------------------------
<input id="div_4_1_1_1_1_1_2-in" class="p-field span12" type="text">
I have tried below code ,
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
WebDriverWait wait = new WebDriverWait(driver, 4000);
wait.until(ExpectedConditions.visibilityOfElementLocated((By.id("div_4_1_2_1_1-lnk"))));
But it's not working. And this iframe has dynamically generated only his title
Output :
Nov 22, 2013 2:52:03 PM org.openqa.selenium.support.ui.ExpectedConditions findElement
WARNING: WebDriverException thrown by findElement(By.id: div_4_1_2_1_1-lnk)
org.openqa.selenium.remote.UnreachableBrowserException: Error communicating with the remote browser. It may have died.
Selenium has one expected condition to solve your problem :
ExpectedConditions.frameToBeAvailableAndSwitchToIt(locator)
I recommend you read this link and this one