I'm working with Genexus 16U11 in C#: I have a web panel with an image variable, when I click a button it should load in the variable an image from a specific URL, so in the event I have
Event 'Dodestra'
&SpeseFoto.FromURL(&targetPath)
EndEvent
Where targetpath is set previously.
It works the first time, but if I change the image in the url, it continues to load always the same image, I need to delete the cache to make it works. As in this program the image in the url has to change very often, this is a problem.
How can I force a reload of the image with the fromURL method?
EDIT: this in Chrome. In Edge and Firefox it correctly sees the new image. I tried to add this Form.Meta.AddItem("pragma","no-cache") but without success
I found a workaround: I can add a random parm to the url, in this way chrome is forced to check again the url&randomn = Random()
&randomn = Random()
&randomx = &randomN * 10000000000
&nomeRandom = &targetPath+"?random="+&randomx.ToString().Trim()
&SpeseFoto.FromURL(&nomeRandom)
Not a lot elegant, but it works
Related
I need to place photos on Indesign pages, few on each of 100 pgs. I use Place function and it causes to the photo to be loaded on the cursor, and then I need to click on the location I want it. But I need it to be automatic! I mean, to finish placing the photos on the page, but it waits to the user to click.
This is the code:
Indesign.Page pg = doc.Pages[1];
Indesign.TextFrame frm = pg.TextFrames[1];
string txt = frm.Contents;
if (txt.Contains("ploni"))
{
app.Place("C:\\User\\Directory\\PhotoFile.png");
}
I have noticed that Indesign.Page has another parameter in its Place function that called "InsertionPoint". But I didn't understand what is it.
Yes, finally I created a rect, then position it, and then place the image inside. Like this:
InDesign.Rectangle rct = pg.Rectangles.Add(doc.Layers.FirstItem(), InDesign.idLocationOptions.idUnknown, pg);
rct.GeometricBounds = new[] { yDown, xDown, yUp, xUp };
rct.Place(#"C:\User\image.png");
I know nothing about C#, but in Extendscript InDesign DOM Page object has place() method. http://jongware.mit.edu/idcs6js/pc_Page.html And it doesn't wait any click from a user.
You can place image at top-left corner of a page this way:
app.activeDocument.pages[0].place("c:/temp/image.jpg")
I believe C# uses the the more or less same object model as Extendscript.
I'm trying to have Selenium take a screenshot of the current page in the webdriver. I'd also like to set the browser's dimensions before this occurs so that the screenshot can capture an image of a specific size.
I use this to change the window size:
webDrv.Manage().Window.Size = new Size(w, h);
And this to take the screenshot:
Screenshot ss = ((ITakesScreenshot)webDrv).GetScreenshot();
ss.SaveAsFile(Path.Combine(m_path, m_filename), ScreenshotImageFormat.Png);
The problem is that on some pages, the screenshot will be taken before the browser has finished redrawing the page.
I cannot use the usual methods of checking (such as using JS to get the document.readyState) because the page is already loaded at this point, so any checks like this return true.
This is only a problem on pages that use Javascript to resize elements based on window size. Pages that use CSS don't have this problem.
I can get around this by taking the entire HTML Body element before and comparing it to after the resize is completed:
webDrv.Manage().Window.Size = new Size(w, h);
int oldBodyHash = webDrv.FindElement(By.TagName("body")).Text.GetHashCode(); //get a hash of the current html body
DateTime nextthink = DateTime.Now.AddSeconds(10); //hard time out incase there is no javascript resizing
while (webDrv.FindElement(By.TagName("body")).Text.GetHashCode() == oldBodyHash && DateTime.Now < nextthink) //wait until hash changes or timeout occurs
{
Thread.Sleep(500);
}
Screenshot ss = ((ITakesScreenshot)webDrv).GetScreenshot();
ss.SaveAsFile(Path.Combine(m_path, m_filename), ScreenshotImageFormat.Png);
But then on pages using CSS to control changing elements, there is no change in the HTML Body.
It seems like it is one or the other, but it's not possible to cover for both possibilities?
I have the same question question JeffC, but to directly fix you problem try adding a
browser.refresh()
in between the window resize and the screenshot-taking.
Looks like there is no actual solution to this other than changing the order in which we perform the operations; essentially the solution is to change the browser dimensions far enough ahead of time to ensure that JS resize activities complete before the screenshot is taken.
I have a print button with id "printButton" and the following attribute:
onclick=window.open('/path/page.aspx');__doPostBack('printButton','')
The code above loads the page on a new window, but I want to load it on the same frame.
I have tried adding several windows as a second parameter in the window.open like '_self', '_parent' or even replaced the whole with windows.location.href='/path/page.aspx'
However none of the above methods worked.
I have even tried browser.Navigate("target url", "frame"); (after adding a Click event on the button), but this also opens a new page.
Any suggestions or workarounds?
Have u tried window.document.location.replace('/path/page.aspx')?
I need to open image in new tab exactly as it's being done by clicking right button on it and then selecting View Image in firefox. Copying pic url and using browser.Goto doesn't give me the result i need due to some tricky javascript. Could anyone give me some suggestions? Thanks
Old question, some answer for reference only.
Get the src attribute for the image you are looking for and then open a new instance of IE with that address (you will probably need to append the base website address plus whatever there is in the src attribute for the image you are looking for. Some code for that:
Image btnLogin = Window.Image(Find.ByName("TheImageNameOrAnyOtherAttribute"));
string imageAddress = btnLogin.GetAttributeValue("src");
var newBrowser = new IE();
newBrowser.GoTo("http://www.somesite.com/"+imageAddress);
I am using a generateimage.aspx page which is used as an image source for an image.
When this page is called i am passing a querystring and then using a Session["abc"] var whoes value is being retruned as a jpg image.
The GenerateImage page is called from another page test.aspx like GenerateImage.aspx?text=P as image source under the img tag .And the value returned is then dislayed i the form of image.
PROBLEM: some time this page is called and some time not.
Thus when the page is not called then the image value that is being returned is that which is assigned to the Session["abc"] var in previous Session.
Please let me know what might be the reason that the page is called sometime and sometime not
And how can I handle this problem.
I think this is a caching issue. By appending a timestamp or a random number to the end of the request url as a querystring will solve this.
Something like
GenerateImage.aspx?text=P&dynstr=" + (new Date()).getTime();
You can disable caching this way:
Response.Cache.SetExpires(DateTime.Now.AddDays(-1));
I agree with #pulse, HTML images are commonly cached by most browsers. So you have two options: 1. Append a random string to the source (not my favorite as it's just a hack) 2. Set the page to force no cache by setting a response header (much better IMO).
Another thing is that I would switch to a handler (ashx page) instead of a standard aspx page for image handling as it has a much lighter footprint/lifecycle and can be easily reused.