Selenium Webdriver - (Java) - working with HTML dialogs - java

Here is the situation:
Click on Import file button (this action will upload a file).
After file upload, then appears a popup (HTML popup). I used driver.switchTo().frame(1); to switch to that popup and click "Next" in that popup.
Clicking Next will navigate user to second step in that popup. Click process commission button in that second step of popup.
After clicking process commission button, then appears a new confirmation popup (HTML popup).
I am not able to click yes in that confirmation popup.
I tried using:
driver.switchTo().frame(0); - did not work
driver.switchTo().frame(1); - did not work
driver.switchTo().frame(2); - did not work
Please suggest any solution.
<form id="Form1" enctype="multipart/form-data" action="ProcessCommission.aspx?i=2115&pn=Manage+Commission&j=2345&prn=Process+Commission" method="post">
<iframe scrolling="no" frameborder="0" src="javascript:'<html></html>';" style="position: fixed; width: 400px; height: 100px; left: 431px; top: 53px; background-color: rgb(255, 255, 255); z-index: 3003;" tabindex="-1">
<div id="RadWindowWrapper_confirm1381733327500" class="RadWindow RadWindow_Windows7 rwNormalWindow rwTransparentWindow" style="width: 400px; height: 100px; position: absolute; transform: none; backface-visibility: visible; visibility: visible; left: 431px; top: 377px; z-index: 3003;" unselectable="on">
<table class="rwTable" cellspacing="0" cellpadding="0" style="height: 51px;">
<tbody>
<tr class="rwTitleRow">
<tr class="rwContentRow">
<td class="rwCorner rwBodyLeft"> </td>
<td class="rwWindowContent" valign="top">
<iframe frameborder="0" name="confirm1381733327500" src="javascript:'<html></html>';" style="width: 100%; height: 100%; border: 0px none; display: none;" tabindex="0">
<div id="confirm1381733327500_content">
<div class="rwDialogPopup">
<div class="rwDialogText">
<div>
<a class="rwPopupButton" href="javascript:void(0); "onclick="$find('confirm1381733327500').close(true);" tabindex="-1">
<span class="rwOuterSpan">
<span class="rwInnerSpan">Yes</span>
</span>
</a>
<a class="rwPopupButton" href="javascript:void(0);" onclick="$find('confirm1381733327500').close(false);" tabindex="-1">
<span class="rwOuterSpan">
<span class="rwInnerSpan">No</span>
</span>

dr.SwitchTo().Frame(dr.FindElement(By.TagName("iframe")));
dr.SwitchTo().DefaultContent();
dr.FindElement(By.XPath("your stuff goes here").Click();
dr.SwitchTo().DefaultContent();//switch back to default content of original page

Try this:
driver.switchto.frame(0)
driver.switchto.frame(confirm1381733327500)

Related

Select from combo box using selenium webdriver without select statement

Html:
<input size="24" autocomplete="off" id="P.Gender" name="P.Gender" class=" x-form-text x-form-field x-form-focus" style="width: 125px;" title="" type="text">
<div class="x-layer x-combo-list " id="ext-gen1943" style="position: absolute; z-index: 11000; visibility: visible; left: 377px; top: 232px; width: 148px; height: 60px; font-size: 12px;">
<div class="x-combo-list-inner" id="ext-gen1944" style="width: 148px; height: 60px;">
<div class="x-combo-list-item ">Unknown</div>
<div class="x-combo-list-item ">Male</div>
<div class="x-combo-list-item x-combo-selected">Female</div>
</div>
</div>
Question: How to select Male/Female/Unknown from above HTML using Selenium webdriver? There is no select class in HTML, so I am not able to use Select.
You can normally use xpath with contains for selecting male/female/unknowm. Otherwise you can ask your developers to add select tag for these dropdowns if they can make the changes.
Example: //div[contains(text(),'Male')]

How can I set value in a text box presented in a Bootstrap Model using placeholder

I want to set value for name using selenium webdriver in firefox (please see below image), but this text box is presented in Bootstrap Model and it doesn't have Id or Name attribute,
it just have placeholder and type attribute (please see second image). I am working on this for last few hours but nothing helpful.
I am trying below code:
> WebElement username = driver.findElement(By.xpath("//input[contains(#placeholder,'Name')]"));
Below is few line from HTML:
<div class="modal welcome__modal is-active">
<div class="modal__overlay welcome__modal__overlay" style="background-color: rgba(71, 70, 86, 0.1);"></div>
<div class="modal__content welcome__modal__content" style="padding: 10px 0px; width: 600px;">
<div style="overflow: auto; width: 100%;"><span style="opacity: 0;">_</span>
<div class="welcome__modal__content__wrap" style="display: flex; flex-direction: column;">
<div class="welcome__modal__content__heading"><a class="welcome__modal__content__heading__logo" style="display: flex; align-items: center; margin-top: 1px;"><img src="/5729a135ccb77ae7a0744b6903af9cb8.svg" alt=""><img src="/6e963a3bd5d0e46cfc51abd29cb5e047.svg" alt="" style="margin: 3px 0px 0px 10px;"><h1 class="sr--only">Primedice</h1></a>
<h3><span>The most <strong>popular</strong> and <strong>trusted</strong> Bitcoin gambling website.</span></h3>
</div>
<form class="welcome__modal__content__form" autocomplete="off"><input placeholder="Name" type="text"><button class="btn"><span><!-- react-text: 971 -->Join <!-- /react-text --><strong>3,241,212</strong><!-- react-text: 973 --> players now<!-- /react-text --></span></button></form>
<div class="welcome__modal__captcha is--hidden">
<div>
<div style="width: 304px; height: 78px;">
<div><iframe src="https://www.google.com/recaptcha/api2/anchor?k=6LeX6AcTAAAAAMwAON0oEyRDoTbusREfJa2vxDMh&co=aHR0cHM6Ly9wcmltZWRpY2UuY29tOjQ0Mw..&hl=en&type=image&v=r20171115120512&theme=light&size=normal&cb=c2gxjjpxcbva" role="presentation" scrolling="no" sandbox="allow-forms allow-popups allow-same-origin allow-scripts allow-top-navigation allow-modals allow-popups-to-escape-sandbox" height="78" frameborder="0" width="304"></iframe></div><textarea id="g-recaptcha-response-1" name="g-recaptcha-response" class="g-recaptcha-response" style="width: 250px; height: 40px; border: 1px solid #c1c1c1; margin: 10px 25px; padding: 0px; resize: none; display: none; "></textarea></div>
</div>
</div>
<p class="welcome__modal__content__login"><span>Already have an account?</span>
<!-- react-text: 978 -->
<!-- /react-text --><strong style="cursor: pointer;"><span>Login here</span></strong>
<!-- react-text: 981 -->.
<!-- /react-text -->
</p>
</div>
<p class="welcome__modal__content__terms"><small><span>By accessing the site I attest that I am at least 18 years old and have read the</span><!-- react-text: 985 --> <!-- /react-text --><span style="text-decoration: underline; font-weight: 600; cursor: pointer;"><span>Terms & Conditions</span></span><!-- react-text: 988 -->.<!-- /react-text --></small></p>
</div>
</div>
Somebody, please help me.
As you mentioned that the text box is presented in Bootstrap Modal Dialog Box so we have to construct a proper xpath with proper wait as follows :
WebDriverWait wait_modal = new WebDriverWait(driver, 10);
wait_modal.until(ExpectedConditions.elementToBeClickable(By.xpath("//div[#class='modal__content welcome__modal__content']//input[type='text' and #placeholder='Name']"))).sendKeys("debanjan");
Try using the below way:
First get the root element and keep it to a WebElement object. Then find the form element and finally send the value to input element.
WebElement elem = driver.findElement(By.cssSelector("div.modal__content.welcome__modal__content"));
//wait until the form is appeared [here apply wait functionality]
WebElement username = elem.findElement(By.className("welcome__modal__content__form"));
username = username.findElement(By.cssSelector("input[type='text']"));
username.clear();
username.sendKeys("John dohn");
You can try to find element by its placeholder:
driver.findElement(By.xpath("//input[#placeholder='Name']"))
Hope it helps you!

How to read graph data using selenium Webdriver

I need to read data from a graph using selenium Webdriver.
The graph on the website looks like:
If I bring my cursor on top of the dot in red box, a pop up appears which gives the CTR and Impressions value at that date.
I cannot do inspect element on this popup.All in the source code, I am unable to see any text similar to 2,790 Impressions value.
How can I read the value of CTR and impressions corresponding to each date.Please help and suggest.
In HTML, I can only see dates like:
<div class="highcharts-axis-labels highcharts-xaxis-labels" style="position: absolute; left: 0px; top: 0px;">
<span style="position: absolute; font-family: "Open Sans",sans-serif ! important; font-size: 11px; white-space: nowrap; color: rgb(112, 112, 112); cursor: default; margin-left: 0px; margin-top: 0px; left: 1146.69px; top: 256px;" opacity="1"><div style="overflow:hidden;text-align:center;text-overflow:ellipsis;white-space:nowrap;width:81px;">**19/11/2015**</div></div>
Kindly suggest.Any help will be appreciated!!
More html:
<div id="widget-5665340308297502-inner" class="widget-data menu firepath-matching-node" data-bind="attr:{id: internal.controlWidgetInnerContainerId}, event:{dblclick: api.editSettings}" style="" data-highcharts-chart="3">
<svg version="1.1" style="font-family:"Open Sans", sans-serif !important;font-size:12px;font-weight:normal;" xmlns="http://www.w3.org/2000/svg" width="1309" height="287">
<div class="highcharts-tooltip" style="position: absolute; left: 146px; top: -9999px; visibility: visible;">
<div class="highcharts-axis-labels highcharts-xaxis-labels" style="position: absolute; left: 0px; top: 0px;">
<div>06/11/2015</div>
</span>
</div>
<div class="highcharts-axis-labels highcharts-yaxis-labels" style="position: absolute; left: 0px; top: 0px;">
</div>

How to select a text from table and click with selenium

In order page when I make a payment, I get the created payment listed in payments list page. The created payment will always list on the first row of the table. I want to know how to get a text “This is Project:
“ and also be able to click on it. Every payment has its own id in a row i.e. Here is the snipped of the table:
<div id="PAYMENT-CONTAINER" style="clear:both">
<div class="list-widget" id="PAYMENT-LIST">
<ul style="visibility: visible;" class="table">
<li id="393118">
<div class="no-expand col0" style="text-align: center; width: 31px;"><input type="checkbox" class="rowSelect" value="393118"></div>
<div class="no-expand col1" style="text-align: center; width: 57px;">
<span class="tag untagged">•••</span>
</div>
<div class="col2" style="text-align: center; width: 155px;">
07/28/2015
</div>
<div class="col3" style="width: 401px;">
5280 FAST PITCH
</div>
<div class="col4" style="width: 344px;">
This is Project:
</div>
<div class="col5" style="text-align: right; width: 213px;">
$25.00
</div>
<div class="col6" style="width: 188px;">
Stacey Smith
</div>
<div class="col7" style="width: 178px;">
In Process
</div>
</li>
<li id="393119">
<div class="no-expand col0" style="text-align: center; width: 31px;"><input type="checkbox" class="rowSelect" value="393119"></div>
<div class="no-expand col1" style="text-align: center; width: 57px;">
<span class="tag untagged">•••</span>
</div>
<div class="col2" style="text-align: center; width: 155px;">
07/28/2015
</div>
<div class="col3" style="width: 401px;">
5280 FAST PITCH
</div>
<div class="col4" style="width: 344px;">
Donations are for good cause
</div>
<div class="col5" style="text-align: right; width: 213px;">
$26.00
</div>
<div class="col6" style="width: 188px;">
Stacey Smith
</div>
<div class="col7" style="width: 178px;">
In Process
</div>
</li>
You can get the text WebElement by using below xpath:
//div[#class='col4']
or
//div[contains(text(),'This is project');
you can use any one of the xpath to find web element.
Something like this:
WebElement element = driver.findElement(By.xpath("//div[#class='col4']"));
//Print text
print(element.getText());
//Click on that element if it is clickable.
element.click();
Xpath selector for your case is: //div[contains(text(), 'This is Project:')]
. For example, if instance of webdriver is called like "driver", then code should be:
driver.findElement(By.xpath("//div[contains(text(), 'This is Project:')]")).click();
If your required text "This is Project:" always appears in first row, then you can try below xpath:-
//li[1]/div[#class='col4']
//to get text:-
driver.findElement(By.xpath("//li[1]/div[#class='col4']")).getText();
//to click on it:-
driver.findElement(By.xpath("//li[1]/div[#class='col4']")).click();

Trying to make an iframe shim work with a CSS drop-down menu over a Java applet

So, I have a page that runs a java applet generated through an external source. I also have some source from another site I own, that uses CSS to create drop-down menus. I am trying to implement the same drop-down style in my new java-applet-laden page.
The problem is, my menu is always layered underneath the java applet without regard for z-layers. I think this is an "answered" issue here: How to display <div> over a Java applet in Chrome. However, the "solution" is a dead link.
I tried modifying the code here: http://midgetontoes.com/blog/2014/05/02/introduction-to-iframe-shim to fit my application.
My implementation fails on multiple levels. First, whenever my shim/drop-down displays, it shifts the content of the entire page down 20-ish px. Second, the drop down menu still disappears under the plugin.
Here are the relevant sections of code:
CSS:
.iframeshim-container {
position:relative;
z-index: 100;
}
header ul.menu li.parent ul {
background:url(dropdown_bg.png) 50% 0 repeat-x #98A2A9;
display:none;
left:0;
margin:0;
padding:10px;
position:absolute;
top:1px;
width:200px;
z-index:100;
}
.iframeshim-container .content-container{
display:none;
margin: 0;
padding: 0;
overflow: hidden;
width: 100%;
height: 100%;
}
.iframeshim-container .shim-iframe{
display:none;
position: absolute;
left: 0;
top: 0;
width: 100%;
height: 100%;
z-index: -10000;
}
header ul.menu li.parent:hover ul {
display: block;
}
header ul.menu li.parent:hover .iframeshim-container .shim-iframe {
display: block;
}
header ul.menu li.parent:hover .iframeshim-container .content-container {
display: block;
}
HTML:
<div class="container maincontainer">
<header class="clearfix">
<nav>
<ul class="menu" id="mainnav">
<li>Home</li>
<li class="deeper parent">Test
<div class="iframeshim-container">
<div class="content-container">
<ul>
<li>Item 1</li>
<li>Item 2</li>
<li>Item 3</li>
<li>Item 4</li>
</ul>
</div>
<iframe class="shim-iframe" frameborder="0" scrolling="no"></iframe>
</div>
</li>
</ul>
</nav>
</header>
<section id="main" class="clearfix">
<div id="content" class="clearfix" style="width: 910px;">
<section id="maincontent">
<APPLET CODE="myCode"></APPLET>
</section>
</div>
</section>
</div>

Categories