Closing a popup box in Google Translate - xpath

I am new to NUNIT and am stumped on how to close a dialog box.
The site I am experimenting with is Google Translate. Part of the code "clicks" on the "Send Feedback Link".
Below is the function I am using:
public void CloseModalWindow(string className)
{
WebController wPage = new WebController(driver);
wPage.waitUntilExistsByXPath(className);
wPage.waitUntilVisibleByXPath(className);
IWebElement clickButtonXPATH = driver.FindElement(By.XPath(className));
clickButtonXPATH.Click();
}
The basic logic is that I am trying to simulate is to click the "X" on the upper right hand side of the Google Feedback popup that appears.
Please note that:
The web driver is FireFox.
I am sending the XPath value (derived from Google Translate directly using FireBug) /html/body/div[3]/div/span[2].
I've also tried using the CSSSelector method instead of XPATH, sending the value span[class='modal-dialog-title'] into the function.
Nunit will in complete without any errors, but the popup does not close as I am anticipating.
Thank you in advance for your input and insight.

From your XPath I see that the "X" is not a natively clickable element - like <a> or <button> are. I experienced that calling Click() on such elements does not what one expects. Instead you could try using the action builder functionality which will simulate a general mouse or keyboard input. Replace
clickButtonXPATH.Click();
with
new Actions(driver).Click(clickButtonXPATH).Build().Perform();

Related

clicking on particular link without using qtp function

Can anybody help me out clicking on particular static link on webpage without using QTP function?
I tried using WebLink after browse.page.WebLink then operation.
Not sure the reason you don't want to use QTP's click function, but you can try to hit the object at the DOM level with Browser().Page().Link().object.click (which really is the same as the B.P.L.Click method but at a lower level).

Searching on pressing enter button using selenium not working with Firefox

I have the below code. What I actually want to do is enter a string in text field and click on enter. Then search results should be displayed.
But here on 'element.sendKeys(Keys.ENTER);' application logs out. I checked with URLs. URLs should be same after searching.But it changes here.
This code works for Chrome and IE. Issue only with Firefox only.I checked the element type to confirm the clicking. It was text box only.
public static void pressEnterKey(WebDriver driver,WebElement element){
System.out.println("Current URL1" + driver.getCurrentUrl());
WebElementType elementType = WebElementHelper.findElementType(element);
System.out.println("Element Type = " + elementType);
element.sendKeys(Keys.ENTER);
System.out.println("Current URL2" + driver.getCurrentUrl());
}
There is a bug report regarding this issue, it seems to be specific with .NET and FireFox.
See here:
https://code.google.com/p/selenium/issues/detail?id=2079
The result would be to use
element.sendKeys(Keys.Return);
If the sole purpose is to click on the "Enter" button, instead of sending "Enter" keys why not click on the respective element.
Just replace the code element.sendKeys(Keys.ENTER); in your code above with either of the below code(s):
element.click();
OR
element.submit();
On another note, as per the definition, sendKeys method is used to type into an element. And, I am pretty sure you can't type into a button. :)

Interacting with VB6 client using hidden control in embedded web browser control

I'm having difficulty trapping a programmatically triggered click event on a hidden button control from a ASP.NET MVC 4 web app inside a VB6 thick client (which is using a web browser control). I'm able to trap the click event itself using the following:
Private WithEvents WebDoc As HTMLDocument
Private Function WebDoc_onclick() As Boolean
Select Case WebDoc.activeElement.iD
Case "A"
Do something
Case "C"
Do something else
End Select
WebDoc_onclick = True
End Function
And this works just fine if the control is visible. But if the control is invisible:
<div class="HideBtnDiv">
<input id="C" name="NoItems" type="button" class="BtnDiv" style="display:none"/>
</div>
and I try to trigger a programmatic click via one of the following:
$("#C").('click');
$("#C").trigger('click');
$("#C").triggerhandler("click");
$("#C").focus();
$("#C").trigger('click');
I'm getting an empty string for the "id" attribute and as a result I can't distinguish which button was clicked. This button serves no purpose other than to indicate to the VB6 app that a certain criteria has been met and that's the reason why I need it to be hidden. Does anyone have any idea why the id is getting stripped? Or is there any other way to communicate back to the client?
I've also tried filtering by element style using
Select Case WebDoc.activeElement.Style
Case "display:none"
Do something else
End Select
but it came back as "[Object]" so no luck there either. Please let me know if there is a way around this.
Thanks,
Lijin
You seem to have tried several ways of dynamically triggering the click event, but did you try the most obvious way:
$("#C").click();
???
But here is what I would do:
1- Make all of your buttons visible, by removing "display:none" from their style
2- Wrap the buttons you want to hide in a new DIV
3- Set "display:none" style in the newly created DIV
4- You can then trigger the .click() event of any button even if not visible by calling $(id).click();
Thanks, Ahmad. Actually I meant .click() not .('click'). Sorry about that.
Anyway, I tried your suggestion and made the button visible and set the style of the wrapping div to display:none but the id attribute was still coming through as an empty string.
However, I did figure out another way to get this to work. If I keep the wrapping div and button as visible and then focus and click when the condition is met and then do a hide(), my problem is resolved!
$("#C").focus();
$("#C").trigger('click');
$("#C").hide();
The button doesn't get displayed and VB6 still passes the id on the click event. The weird thing is it requires the focus() call to still be made. Without it, I'm back to square one. Not sure if this is a bug.

How to handle google search ajax data using selenium

How to handle google search ajax data using selenium (Type some string in google search, do not press enter key and check matching string data in search text box) ? How to get this data using selenium RC/Webdriver ?
If you know that the action of some event (e.g. sendKeys, onClick, whatever) is going to trigger some event - like an Ajax request - you should be using waitFor until your condition is met (see the Advanced Usage guide).
To avoid supplying a brittle timeout threshold on your test, you may want to call this in a Poll implementation, say once every 500ms 10 times for example, and then pass/fail accordingly
FitLibraryWeb has some nice, clean abstractions for this, but you'd need to use Fitnesse of course
Thank u friends .. I am able to run a google search from selenium example code using firefox driver : http://seleniumhq.org/docs/03_webdriver.html#introducing-the-selenium-webdriver-api-by-example
Now i am trying to click on 'Change Location' available in left side pane after getting the search result but no luck. Code sample :
WebDriver driver = new FirefoxDriver();
driver.get("http://www.google.com");
WebElement element = driver.findElement(By.name("q"));
element.sendKeys("Cheese!");
element.submit();
WebElement expandLocation = driver.findElement(By.id("expand_location_link"));
expandLocation.click();
Debug info:
In view source i am not able to see the element expand_location_link but is visible in element inspect section of firefox/chrome or after saving the page from browser to local system.

How can I know what element is clicked in IE?

I'm automating IE with watir, and I want to know what html element(s) are clicked (selected). Can this be done using watir? win32ole? In a last chance, without ruby?
Something like:
Click a button -> button with id=213 and class=btn_class was clicked.
Click a text field -> text field with id=123 and value=my_text was clicked.
Try one of the recorders, Selenium IDE for example.
I'm not sure if I completely understand either, but would a custom function like this work?
def click(item, how, what)
#browser.item(how, what).click
puts "#{item} with #{how}->#{what} was clicked"
end
click("button", ":id", "awesome")
Edit: If you're attempting to identify page elements so that you can then use them in a Watir script, the Developer Toolbar is perfect for this application, much like Firebug for Firefox.
http://www.microsoft.com/download/en/details.aspx?id=18359
Your comment to me & your response to Zeljko appear to contradict each other. If you want to use WATIR for this task, the code above will execute a mouse click and post the information to console. The only other way to get information is to locate the object in WATIR and fish for more details:
object = #browser.button(:name, /myButton/)
object.id
object.title
object.status
object.height, etc.
or
#browser.divs.each do |div|
puts div.id, div.title
end
I'd recommend a strong look at the capabilities of the various developer tools, such as are provided with Chrome, Firefox, and IE. those are generally the best means to get this kind of information.
Watir is really about driving the browser, and getting info out of the DOM. it's not really setup to report on manual interactions with the browser.

Resources