Hi what I like to do is:
Create in WPF xaml a Grid like that: <_Grid Name="gridWeb">
Open a GeckoFX45 Firefox Browser in this Grid (add the created Geckofx Window as Child to the grid)
Automate this exact Browser in my Grid with Selenium.
I have made a lot of researches on that Problem and I found some articles like https://nhabuiduc.wordpress.com/2014/09/18/geckofx-net-webbrowser-setup-and-features/ on how to solve my issue. With that article I had success to solve point 1 and 2 but with old Version of Geckofx.
I have tried out tons of things, but nothing which included all requirements for my Tool.
Does anyone know if this is even possible?
If yes, does anyone know on how to combine all those 3 requirements with an actual version of Geckofx 45?
Is there any particular reasony why you want to add this browser to Selenium IWebDriver? (like e.g. lots existing code written for IWebDriver?)
If not and you simply want to have an automated browser then you can do much more automation using GeckoFx API.
For example:
GeckoWebBrowser Browser => GetBrowserInstanceSomehow();
...
//get element reference
GeckoInputElement textBox =
this.Browser.Document.GetElementsByClassName("inputBox").FirstOrDefault() as GeckoInputElement;
//set value
textBox.Value = "Something";
GeckoHtmlElement btn = this.Browser.Document.GetElementById("submitButton") as GeckoHtmlElement;
//interact
btn.Click();
You can do virtually everything with it - execute scripts, send POST requests, override CSS, evaluate / change / remove nodes, navigate, handle navigation events etc.
Related
I have following problem. I run test on Firefox and Chrome. On Firefox test run correctly but on Chrome SauceLabs give a message:
unknown error: Element is not clickable at point (717, 657). Other
element would receive the click: <div class="col-md-9 col-sm-12"
style="margin-top:8px;">...</div> (Session info: chrome=36.0.1985.125)
(Driver info: chromedriver=2.10.267521,platform=Windows NT 6.3 x86_64)
I choose element by unique css selector in both test in the same way:
driver.FindElement(By.CssSelector("button.btn-xs:nth-child(1)")).Click();
Any ideas what is wrong here?
I am assuming that you have the correct element you need, ie the XPath is correct.
Here are few ways out:
Try to Click on the parent element instead.
Try .Submit() instead of .Click()
Try to execute the JavaScript that will be executed on the OnClick event of the element you are trying to click.
I have used the 3rd way with success all the time.
Another one
Do a .SendKeys(Keys.Enter) on that element (or a Space key)
Since you've tagged the question as Google-Chrome too - I suppose that this is happening mostly with ChromeDriver. I had the same issues with one of my previous projects (Asp .Net MVC). I found that when some elements are not visible for this Driver if they are not in the screen_visible_area. Please note that they are loaded (HTML, CSS3, JS etc.) properly.
So after a lot of reading and testing, I found that my workaround is simply scroll to the WebElement - so it is in the visible part of the screen. Actually this issue was not for all elements and I didn't find better solution for it.
unknown error: Element is not clickable at point (..., ...)
Is not descriptive error for this case, because like you I also thought that is Selector-related.
Just to be full answer - I had the same problems with IEDriver too. My implementation was to use the Browser scroll down/up options and just "send the screen" where the problematic element is.
Simple JSExecutor code that you can use:
WebDriver driver = new FirefoxDriver();
JavascriptExecutor jse = (JavascriptExecutor)driver;
jse.executeScript("window.scrollBy(110,350)", "");
or
jse.executeScript("scroll(0, 250);");
or
driver.executeScript("window.scrollBy(110,350)", "");
Other topic-related useful resources are here.
Update
When it comes to the .sendKeys() I also used the browser accessibility features. All you need to do is just count how many TAB clicks your test need in order to get to the targeted web_element. Then just call .click().
Try this simple code:
element.sendKeys(Keys.TAB);
or
element.sendKeys("\t")
or
Actions builder = new Actions(driver);
builder.keyDown(Keys.TAB).perform()
I realize this is a super old question, but it came up while searching a nearly identical problem in the present day. After attempting many of the fixes described here and getting new exceptions for my trouble (mostly stale element and http request timeouts) I stumbled across this issue on Selenium's GitHub.
As described in the post, Chrome had advanced beyond the abilities of my version of chromedriver.exe--my v2.30 driver had known issues with clicking elements due to changes in Chrome v61 scrolling mechanics. Updating to the latest chromedriver.exe solved all my problems.
tl/dr: ensure your version of chromedriver is compatible with the version of Chrome being tested.
I was getting issue that login button is not clickable in chrome even xpath was correct. after browsing many sites, i came to the solution - use .submit() instead of .click() and it worked perfectly.
driver.findElement(By.xpath("//button[#id='loginBtn']")).click();
driver.findElement(By.xpath("//button[#id='loginBtn']")).submit();
If you're doing anything complicated in your CSS, Chrome can get confused (this has happened to me) and think that the element you're trying to click is covered by another element even though this is not the case.
One way to resolve this is to help Chrome understand the situation correctly by adding z-indexes (you'll need to add relative or absolute positioning also) to unambiguously place the correct element on top of the other.
For me, it was creating this command instead.
driver.FindElementByXPath("id('gender1')").SendKeys(Keys.Space);
For my case, I was interacting with radio control.
I have had this problem on FF. This issue happens when your field is not in the view area. The slick way to resolve this issue is to zoom out your browser:
TheNotClickableField.SendKeys(Keys.Control + "-" + "-");
you might want to zoom out more or less according to your page size.
I.
If the button is on the bottom of the page, the following code could be used to get you to the bottom via JavaScript from where the click can be executed:
(driver as IJavaScriptExecutor).ExecuteJavaScript("window.scrollTo(0,document.body.scrollHeight - 150)");
The same action could be done via C# with the Actions class provided by Selenium.
This will get you to the bottom of the page----->
new Actions(Driver).SendKeys(Keys.End).Perform();
Keys.End could be switched with Keys.PageDown // Keys.Space
II.
If you want to get to the exact position of the element you can:
1.Get the element's Y location---> var elementToClick = driver.findElement(By.{Anything}(""));
2.Execute the following JS---> (driver as IJavaScriptExecutor).ExecuteScript(string.Format("window.scrollTo(0,{0})", elementToClickYLocation.Location.Y));
3.Click the element---> elementToClick.click();
Ok, this should be easy, but I cannot seem to figure it out:
How do I identify and access the new post area (from the Dashboard) in WordPress, using selenium in VS/.Net?
I can access the title field easily by ID, like this:
Driver.Instance.FindElement(By.Id("title")).SendKeys("Sometitle");
But, looking at the page source, I cannot figure out how to access the post body.
In recent versions, I believe, there was an iframe, and it could be accessed like this:
Driver.Instance.SwitchTo().Frame("content_ifr");
Driver.Instance.SwitchTo().ActiveElement().SendKeys(body);
...but this doesn't work anymore, and looking at the source it seems that this has been changed.
So - does anyone know how to do this in recent versions of WordPress?
EDIT: It turns out that I was wrong; there IS indeed an iframe named "content_ifr". So the new question is: Why doesn't the above code work? It's supposed to switch the focus to the content frame, but it doesn't.
try
Driver.FindElement(By.XPath(""));
to find XPath in google chrome right click on element->Inspect element, then click on "Copy XPath".
Hope it helps!
I'm programming in WPF/C# VS2012/2010. I was trying to make an application where you can click on a button to login to an account. The very first webbrowser i used was C# System.Windows.Forms.WebBrowser.
It was fine all methods was nice and simple to use:
Browser.Document.GetElementById("Email").SetAttribute("value", "xxx");
Browser.Document.GetElementById("signin").InvokeMember("Click");
or
HtmlElementCollection textArea = Browser.Document.GetElementsByTagName("textarea");
foreach (HtmlElement element in textArea)
{
if (element != null)
{
element.Focus();
element.InnerText = "Very nice :]";
}
}
This webbrowser is very simple to use, but it is not good enough: it crashed, doesn't use Active-X, HTML5, Silverlight, and much more... So the next one I was trying to use it was "Awensomium".
This is a good webbrowser, no crashes and can easily use all that things I described above, but it's not so simple to use, it doesn't have methods to click buttons, or anything and I can't figure out how I can do this.
Do you know some webbrowser search engine for WPF/C# that allows me to click button etc... and using Active-X,HTML5 and other technologies?
If you are developing in WPF, you shuld use System.Windows.Controls.WebBrowser instead of Forms.WebBrowser. It uses your installed instance of Internet Explorer, so features depend on your IE version. If you upgrade to IE9 you'll be able to show and handle html5,css3 .. items. But if you like Awesomium, then you should try this: http://wpfchromium.codeplex.com/ (there are some examples also) .
We have automated a few test cases using the Ranorex automation framework for a Silverlight web application. These test cases involve clicking buttons in order to invoke certain messages on the screen. In order to grab the button on the screen, we first create an Ranorex button object and then point it to the appropriate element using Ranorexpath. Then, we use the RanorexButton.Click() event to click the button. However, this event is unreliable. It works sometimes and at other times the button is not clicked. When the button is not clicked, we have to run the test case again from the start. What are we doing wrong? If this is a known problem of ranorex, please suggest workarounds.
I was facing the same problem but I am able to resolve the problem by introducing a Validate.Exists(infoObject) just before the click. Please make sure that you pass infoObject of your button or any element in Validate.Exists API.
Example:
Validate.Exists(repo.MyApp.LoginBtnInfo);
var button = repo.MyApp.LoginBtn;
button.Click();
With regards,
Avinash Nigam
I haven't heard about such a problem with Ranorex yet, maybe this is just a timing issue.
You could add a Validate.Exists(yourButton) right before the click, this ensures that the click is performed after the button was successfully loaded.
If it is a WebElement you could also use the PerformClick() method instead of the normal Click() method.
There are also different methods which will ensure that the button is in the visible area and has focus, like the EnsureVisible() or the Focus() method.
You will find the available methods of the used adapter in the online API of Ranorex.
If the Button is not within the area you can see without scrolling, you can use a
var button = repo.Buttons.button1;
button.EnsureVisible();
button.Click();
In this way the button is forced to be watched.
It might as well be an issue with the xpath and element Id-s.
If you have changing element Id-s even when the page is navigated away from and moved back (for example we have this issue with SAP related components) you might need to make a more robust xPath path variable using regular expressions.
Try to find object and parts of the path that do not change (eg. "iFrame id="MainContent"" or "btn id="ID_XXXX_Search_Button"") - ofcourse this will only help if the issue is within this.
Ranorex Regular Expression info can be found here: http://www.ranorex.com/support/user-guide-20/ranorexpath.html#c3294
A quick example of what I'm talking about:
Let's say we have an input field that has a changing ID in it's name:
US_EL.ID_F2B49DB60EE1B68131BD662A21B3432B:V_MAIN._046A-r
And I know that the part in the Id that doesn't change is:
:V_MAIN._046A-r
I can create a path for this searching the element by the ending of the elements' id that doesn't change using regular expression:
/dom[#domain='test.example.com']//iframe[#'identifier']//iframe[#'identifier2']//input[#id**~'^**:V_MAIN._046A-r']
The bold part will specify to search for an input element with an Id that ends with ":V_MAIN._046A-r".
An issue that might arrise from this is if you have elements using partially the same names you might get multiple elements returned for the same path. So it's wise to add a few more certain points to the path (eg. "iframe[#'identifier2']") when this issue arrises.
I am writing a simple personal app that has a browser control and I want it to automatically "Refresh" gmail to check it more often than it does by default. There are monkey scripts that do this but I'm trying to add my personal style to it.
Anyhow, I've looked around and found everything but what I can do in csharp using the browser control.
I found this:
// Link the ID from the web form to the Button var
theButton = webBrowser_Gmail.Document.GetElementById("Refresh");
// Now do the actual click.
theButton.InvokeMember("click");
But it comes back with null in 'theButton' so it doesn't invoke anything.
Anyone have any suggestions?
It's been awhile since I've used JavaScript, but given the other answers and comments that there is no real ID associated with the element, could you do something like the following:
Search all Div's with an attribute of Role == 'Button' and an InnerHtml == 'Refresh'.
Once the correct InnerHtml is found, get the Element.
Invoke the click on the found Element.
Again, this may be blowing smoke, but thought I'd throw it out there.
edit: Just realized you are doing this with C# and a browser control; however, the concept would still be the same.
The best suggestion I could give you at this point involves an existing API that is used for .NET web browser based automation:
http://watin.org/
Since the div tag with the desired button really only seems to identify itself with the class name, you could use the Find.BySelector(“”) code included with the most recent version of watin.