Looking for way to pick elements with Selenide inside the document which is render using ReactJs.
I need to access xpath //h1/span[text()=' 1'] which is inside the document and Iframe. Is there a way to get that element and switch back to the main window?
Page contents look like below (Same page content in both images due to it being too long):
I'm able to succeed this using below method, Again but I got TimeoutException on time to time.
[1627896042.179][SEVERE]: Timed out receiving message from renderer: 30.000
public WebDriver getFrame(){
try {
return Wait().until(frameToBeAvailableAndSwitchToIt(iFramePth));
}catch (Exception ex){
System.out.println("error in get Frame");
ex.printStackTrace();
return null;
}
}
For that, I used the below method before calling to the above one. (Check Iframe is available)
iFramePthElement.should(Condition.appear, Duration.ofSeconds(TIME_OUT));
But even now it getting failed sometimes same error.
[1627896042.179][SEVERE]: Timed out receiving message from renderer: 30.000
To switch back to the main window, you can just do something like this:
switchTo().parentFrame();
This will take you back out of the iFrame context and back onto the main site (or parent page).
As for the Timeout issue, I think this has been covered here: https://stackoverflow.com/a/60167733/9350566
Related
Let say I have multiple pages, one of those is main page that simply display logo styles, text etc, the other pages uses multiple grids, do I have to configure/retrieve the data for other pages on startup even if this is not necessary?
Yes you can do that easily in any controller action method and based on whatever parameters and logic you want, and it is the same as you do in the start up configuration.
The only issue I faced while doing that is in this line:
MVCGridDefinitionTable.Add("gridName", def);
because this lines will throw an error if the grid already added and defined, and the bad news that the solution I found so far is not a good solution as you can see in this post: https://github.com/joeharrison714/MVCGrid.Net/issues/62
You can check for existing grid using
MVCGridDefinitionTable.GetDefinition method. This will throw an
exception if there is no grid and returns the grid if there is grid.
After getting the grid, set the RetrieveData property on the grid for
changing the data elements.
Something like this:
//check if grid already exist
// https://github.com/joeharrison714/MVCGrid.Net/issues/62
try
{
MVCGridDefinitionTable.GetDefinition<YOURTYPE>("gridName");
}
catch (Exception ex)
{
MVCGridDefinitionTable.Add("gridName", def);
}
*** If you got a better way please share it.
I'm new to java and webdriver. My web-applications adds some data to a table on a webpage. If the addition is successful, a new web page is opened and the success message is displayed on the new page. If the addition is not successful, a javascript alert is thrown. After accepting the alertHow do I check the presence of an the message on the new webpage using webdriver?
If it is opening in new window you need to switch the control to new window first
Find the logic here to switch the control between windows
After switching the control to new window you can verify whatever you want. Either element or text.
isElementPresent? method logic here .
isTextPresent? method logic here.
If I understand the question correctly, after sending the data to the table, if the sending is successful then the window is loaded with a new webpage else an alert appears once you accept the alert the window is loaded.
After sending the data, check for the presence of the alert, if the alert is present then accept it. Next is verifying whether a text is present in the newly loaded webpage or not.
public void isAlertPresent(){
try {
driver.switchTo.alert().accept();
}
catch ( NoAlertPresentException e ){
}
System.out.println(driver.findElement(By.tagName("body")).getText().contains("Expected Message"));
If the location where the message appears is static then I would suggest you to use a better approach than the above like if an element has that text
WebElement element = driver.findElement(By.id("elementID"));
System.out.println(element.getText().trim().equals("Expected Message"));
I have a web application that creates a graph on another aspx page. Sometimes the graph cannot be created to specification because there is an error in the user specification (such as a string where an integer was expected).
I would like to immediately pop up an alert window telling them that something went wrong when I was trying to render the graph.
The thing is, I don't know how to immediately check to see if I should insert a script for an alert window. Once my code on "chart.aspx"(image URL) is executed, I don't know how to immediately check if anything went wrong from the main page. I know it happened in the code in chart.aspx, but other than not to not render the image or render a different image, I don't know how to tell the user before another postback. I would really like to see if there is any sort or event or stage in the page lifecycle after one of the images is rendered.
If this is not possible, how can I chart.aspx convey an error message to default.aspx if it is simply an image. Maybe some sort of Response.Write(...?)
Thanks again guys.
Maybe you could try monitoring the image's load events and handle onabort and onerror via javascript?
http://www.w3schools.com/jsref/dom_obj_image.asp
Image Object Events
Event The event occurs when...
onabort Loading of an image is interrupted
onerror An error occurs when loading an image
onload An image is finished loading
The old school way of doing this would be to render your image tag like below:
<img src="chart.aspx" onerror="alert('Image failed to load because XYZ.');" />
Nowadays, I'd recommend you use jquery, something like this:
<img src="placeholder.gif" class="chart" alt="chart">
<script type="text/javascript">
jQuery(function($) {
var img = $(document.createElement('img'));
img.on('error', function() { alert ('...'); });
img.on('load', function() { $('img.chart').attr('src', img[0].src); });
});
I have a timer in my application. For every 30 min, it will hit the web services and fetch the data and updates the UI. The application was working fine till yesterday. Suddenly, because of some issue, the web services were not available for some time. During that period, Application displayed the RPC Error multiple times(More than 100 alert boxes) in alert window. Because of this alert boxes, my application was hanged and i was not able to do anything.
I have tried several approaches, but nothing worked.Finally, I have tried to use a flag. In all the approaches, this looked promising. so i have implemented it.Basically, in this approach whenever we open an alert we will set a flag.While opening and closing alert we will reset this flag. But it didn't work as expected. Is there any approach, which can help us in avoiding multiple alert windows.
Please help me, to fix this issue.
I would write wrapper for opening alerts, and use only this wrapper, not Alert.show in the code:
public class AlertWrapper {
private static var lastAlert:Alert;
public static function showAlert(text:String, title:String):void {
if (lastAlert) {
PopUpManager.removePopUp(lastAlert);
//or
//return; //ignore last alert
}
lastAlert = Alert.show(text, title, null, 4, onAlertClose);
}
private static function onAlertClose(event:CloseEvent):void {
lastAlert = null;
}
}
Imports are missing, but I hope the idea is clear.
I have a greasemonkey script that opens an iframe containing a form from a different sub-domain as the parent page.
I would like to refresh the parent page when the iframe refreshes after the form submission
I am at the point where I can execute a function when the iframe refreshes, but I cannot get that function to affect the parent document.
I understand this is due to browser security models, and I have been reading up on using postMessage to communicate between the two windows, but I cannot seem to figure out how to send a reload call to the parent with it.
Any advice on how to do that would be very helpful
thanks
Use:
window.parent.postMessage('Hello Parent Frame!', '*');
Note the '*' indicates "any origin". You should replace this with the target origin if possible.
In your parent frame you need:
window.addEventListener('message', receiveMessage, false);
function receiveMessage(evt)
{
if (evt.origin === 'http://my.iframe.org')
{
alert("got message: "+evt.data);
}
}
Replace "my.iframe.org" with the origin of your iFrame. (You can skip the origin verification, just be very careful what you do with the data you get).