I am trying to open a new window on click of a link using CEF.
I have given the href and target as _blank in my HTML.
New page is opening fine when Internet is available, but opens a blank window when connection is down. I tried debugging and as far as I understand , if the OnBeforePopUp function returns false, there should be no problems.
My HTML code line is
<span class="sr-only">Click here for Google</span> Help
and in my code,
public bool OnBeforePopup(IWebBrowser browser, string url, ref int x, ref int y, ref int width, ref int height)
{
return false;
}
CEF will obviously show blank page when url is down. What you can do is, design one html page to show when site is down and show that static page in CEF.
Related
I am using the ReportViewer in my WPF application and I am trying to get a custom protocol to work with the application. So I get the ability to open sub-programs inside my application when a url is clicked inside the ReportViewer.
When I click on the custom-protocol-url (inside the ReportViewer) nothing happens.
When I open the same report via the Web-Browser, my URL works flawlessly.
It seems like the ReportViewer doesn't allow custom protocols? Has anyone experienced that aswell? Is there any documentation on that?
http, https and mailto are working in the ReportViewer.
I am just adding an Action in the Report pointing to my url
customurl://123
Url definition:
[HKEY_CLASSES_ROOT\customurl]
#="URL: customurl Protocol"
"URL Protocol"=""
[HKEY_CLASSES_ROOT\customurl\shell]
[HKEY_CLASSES_ROOT\customurl\shell\open]
[HKEY_CLASSES_ROOT\customurl\shell\open\command]
#="\"C:\\Extra Programme\\TestAlert.exe\" \"%1\""
Testalert (just the test-program by microsoft):
static string ProcessInput(string s)
{
// TODO Verify and validate the input
// string as appropriate for your application.
return s;
}
static void Main(string[] args)
{
Console.WriteLine("Alert.exe invoked with the following parameters.\r\n");
Console.WriteLine("Raw command-line: \n\t" + Environment.CommandLine);
Console.WriteLine("\n\nArguments:\n");
foreach (string s in args)
{
Console.WriteLine("\t" + ProcessInput(s));
}
Console.WriteLine("\nPress any key to continue...");
Console.ReadKey();
}
I have looked into the code of ReportViewer and found an if statement, that checks if the url starts with either http:// or https:// or mailto:.
It gets this information with Uri.UriSchemeHttp, Uri.UriSchemeHttps and Uri.UriSchemeMailto
So you could overwrite eg. Uri.UriSchemeHttp with "customurl" (if your url is customurl://123) before rendering the report.
var field = typeof(Uri).GetField("UriSchemeHttp");
field.SetValue(null, "customurl");
The more elegant solution would be, to use a webbrowser control and just show the SSRS Web-Page
I have a frame and inside that clicking a button opens an iFrame. my frame selection seems to work and i know my XPath is good (because it works in chrome) but my test always fails with
OpenQA.Selenium.WebDriverTimeoutException: Timed out after 5 seconds ---> OpenQA.Selenium.NoSuchElementException: no such element: Unable to locate element: {"method":"xpath","selector":"//em[.='Job Selector']"}
attached are some images that show HTML and sources.
in my code I'm using:
// wait for menu frame to appear
wait.Until(ExpectedConditions.FrameToBeAvailableAndSwitchToIt(By.XPath("//frame[#id='menu']")));
// do a bunch of stuff
driver.SwitchTo().DefaultContent();
wait.Until(ExpectedConditions.FrameToBeAvailableAndSwitchToIt(By.XPath("//frame[#id='master']")));
// Add to running jobs: open iFrame
driver.FindElement(By.Id("ctl00_cphMain_cmdAdd")).Click();
//driver.SwitchTo().DefaultContent(); tried with and without this
wait.Until(ExpectedConditions.FrameToBeAvailableAndSwitchToIt(By.XPath("//iframe[#name='JobWindow']")));
// wait for SelectJob Window to appear tried several elements
//wait.Until(ExpectedConditions.ElementIsVisible(By.Id("RadWindowWrapper_ctl00_cphMain_JobWindow")));
wait.Until(ExpectedConditions.ElementIsVisible(By.XPath("//em[.='Job Selector']")));
Any suggestions on what I'm doing wrong
Finally got this to work:
wait.Until(ExpectedConditions.FrameToBeAvailableAndSwitchToIt(By.XPath("//iframe[#name='JobWindow']")));
IWebElement body = driver.FindElement(By.TagName("body"));
body.Click();
// wait for SelectJob Window to appear
IWebElement SaveButton = wait.Until(ExpectedConditions.ElementToBeClickable(By.Id("cmdSave")));
SaveButton.Click();
Without the body.click, no luck
Props to Jainish: https://stackoverflow.com/a/41500131/1667188
I have a situation(mentioned below) due to which my selenium script is failing. Can someone help me?
I have a webpage where there is a save button, clicking on save button opens a new popup window. My requirement is to switch to the new window and click on one of the buttons(in the new window) which will automatically close the window and navigates to some other page. I have written a code which actually works fine but sometimes due to the application problem the new window is not getting closed. And due to this my script is failing. Here is the code I have used.
public void test() {
// i have two pages gets involved in this scenario
driver.get("some url"); // user is in page 1
// clicking on save button
driver.findElement(By.xpath("some xpath")).click(); // a new window opens
Set<String> winIDS = driver.getWindowHandles();
if (winIDS.size() > 1) {
Iterator<String> it = winIDS.iterator();
it.next();
String childWindow = it.next();
driver.switchTo().window(childWindow);
driver.findElement(By.xpath("some xpath")).click();
//after clicking on this button the user is navigated to page2
}
// after clicking on the button in the new window the new window gets closed and the user is navigate to page 2 as mentioned before.
// To validate if that has happened i am using the below code so that my test case flow wont be stopped. But
// the code is getting hanged at the new window as the app fails to perform the button click action on the new window.
winIDS = driver.getWindowHandles();
if(winIDS.size() > 1)
{
Iterator<String> it = winIDS.iterator();
it.next();
String childWindow = it.next();
driver.switchTo().window(childWindow);
driver.close();
//i m making the test failed here as the new window is not closed.
}
}
Looking at your code, I can see that you do twice the iteration to next window:
it.next();
String childWindow = **it.next();**
The second it.next() is obsolet.
Hope this solvs your issue.
I need to ebed a web browser in a Wpf app, I tried with the one from the toolbox but get some issues and went to CefSharp.
public MainWindow()
{
InitializeComponent();
BrowserSettings settings = new BrowserSettings();
Cef.Initialize(new CefSettings());
CefSharp.Wpf.ChromiumWebBrowser webBrowser = new CefSharp.Wpf.ChromiumWebBrowser();
licence_grid.Children.Add(webBrowser);
webBrowser.Address = "http://myurlToLoad the page";
}
The problem is when I used a normal url the page load.
But when I used the url I intend to use and whith which the user enter his user and password in a browser pop up (I mean not a pop up from the website) . I get an error with this page take yoo much time to load and nothing else.
Can someone give me some tracks to follow...
Thanks
It sounds like the popup you are referring to is in fact the site prompting for basic authentication.
In that case you need to provide an IRequestHandler.GetAuthCredentials handler.
As the question & answer is very old and i would like to give the latest update on this solution, there is slight change as per original solution suggested.
anybody consuming cefsharp need to implement the authentication dialog. and changes in method is
bool IRequestHandler.GetAuthCredentials(IWebBrowser browserControl, IBrowser browser, IFrame frame, bool isProxy,
string host, int port, string realm, string scheme, IAuthCallback callback)
{
//NOTE: If you do not wish to implement this method returning false is the default behaviour
// We also suggest you explicitly Dispose of the callback as it wraps an unmanaged resource.
// shyam - original implemenation.
//callback.Dispose();
//return false;
bool handled = false;
// Instantiate the dialog box
AuthDialog dlg = new AuthDialog(host); // create new dialog with username and password field.
// Open the dialog box modally
dlg.ShowDialog();
if (dlg.DialogResult == System.Windows.Forms.DialogResult.OK)
{
// The user did not cancel out of the dialog. Retrieve the username and password.
callback.Continue(dlg.UserName,dlg.Password);
handled = true;
}
return handled;
}
Iam trying to switch between browser ie on click of a button it launches a new browser it
is finding the handle ..the problem is it is not able to find the object inside the new browser searched with id,xpath,name etc can some one give me any suggestion on the same.
also it is able to match the url as well.
please provide me the solution on the same.
below is the code.
//Previous screen
Set windows = driver1.getWindowHandles();
driver1.findElement(By.id("findButton")).click();
//switching handle for the new screen
driver1.switchTo().window("Customer Search");
driver1.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);
int i = 1;
while(i<= 10){
for (String handle : driver1.getWindowHandles()) {
String myTitle = driver1.switchTo().window(handle).getTitle();
System.out.println("myTitle value : " +myTitle);
//customer search is the new window title
if(myTitle.equalsIgnoreCase("Customer Search")){
driver1.manage().window().maximize();
//if i pass the right url of the screen that is also matching here i have given dummy("sshsj")
if(driver1.getCurrentUrl().equalsIgnoreCase("sshsj"));
{
System.out.println("Url is matching");
//But not able the recognise the object on the new window.
driver1.findElement(By.xpath("html/body/left/form/table/tbody/tr[2]/td[1]/input")).sendKeys("kamal");
}
You can use JS to open a new window, it's faster.
IJavaScriptExecutor jscript = driver as IJavaScriptExecutor;
jscript.ExecuteScript("window.open()");
Then to switch windows, use the window handles:
List<string> handles = driver.WindowHandles.ToList<string>();
driver.SwitchTo().Window(handles.Last());
driver.get(url);
driver.findElement(By.xpath("html/body/left/form/table/tbody/tr[2]/td[1]/input")).sendKeys("kamal");
It is possible that the element may be present inside an iframe. In that case, you need to switch to that iframe before you can access any element inside the iframe.