I am using Selennium Webdriver to automate a click of a PDF download button. I used various ways to click the button, but it seems to throw a Jscript error:
Message: Unexpected call to method or property access.
Line: 17
Char: 29094
Code: 0
URI: http://uat.mysite.com/Scripts/jquery-1.6.2.min.js
My click code (tried these both):
driver.findElement(By.xpath("//div/a[contains(text(), 'Download PDF')]")).click();
or
driver.findElement(By.xpath("//div[#class='paginationWrap']/a[#class='redBlock']")).click();
The html:
<div class='articleFoot'>
<div class='paginationWrap'>
<a class='redBlock' target="_blank" href='/DownloadMedia.aspx?media={625B459D-C085-48C5-931C-71BE03786236}'>
Download PDF
<span class='icon pdf'></span>
</a>
</div>
</div>
Both of these xpath expressions are ok.
If the exception is really not from the jquery script (is it not?), then it's most likely that Selenium can't really download files. Yet.
Still, besides the HtmlUnitDriver (whose behaviour I don't know), the browser should offer you a download dialog. Try another Driver, then look for errors elsewhere.
You can do some tricks to achieve a file download alternatively, my personal favourite is this downloader, but there are a few more ways like getting and setting up Download Statusbar into Firefox, some Robot moves and so on. But do you really need to?
This might help you:
WebElement state = driver.findElement(By.xpath("//div/a[contains(text(), 'Download PDF')]"));
Actions builder1 = new Actions(driver);
builder1.moveToElement(state).click().perform();
Related
I'm beggining to try DoneJS, starting with de Chat Demo. After copying the instructions, "home" page shows correctly, but the "Start Chat" button is not working. After some digging, i found this messages on Console: can-log.js:98 16: Unable to find helper "routeUrl".
When I oppend the source-page, the <a> tag that should link to the other page is like "<a class="btn btn-primary btn-block btn-lg" href>Start chat</a>, without the href clause completed.
Probably I have missed something when I copied. Coincidentally, on VSCode, exactly the import route from 'can-route' on app.js is showing a ... symbol and saying that it was not possible to find some declaration module for can-route.
Here is my declaration:
Start chat
Sorry about that, my mistake. I missed <can-import from="can-stache-route-helpers" /> command. Now it is ok.
The "Add new item " link on any list in Sharepoint2010 shows up a window/frame. I want to be able to find textfields, write into them and perform other operations in the window/frame. Currently i am unsuccessful with the following methods:
BrowserInstance.SwitchTo().Frame(index) --- Exausted all indexes.
BrowserInstance.SwitchTo().Window() ---
The HTML looks something like:
<Div class=some class>
<Iframe frameborder=0 ..........>
</iframe></div>
Selenium Webdriver (c#) identifies the div (class= some class) but not the Iframe which unfortunately holds all the fields and buttons.
Any thoughts?
I failed to do this using selenium. So i used watin code within Selenium Test. It may not be a very good idea but Watin seems to be identifying the SharePoint 2010 iframes pretty pretty well.
IWebDriver.SwitchTo().Frame(1);
works for me.
Are you using WebDriverWait after this method? You have to wait until modal dialog loads:
webDriverWait.Until(drv => _driver.SwitchTo().Frame(1));
// Locate 'Name' field.
webElement = webDriverWait.Until(drv => _driver.FindElement(By.XPath("//textarea[#title='Name']")));
I'm using Webdriver to test my web application. When I work with FireFoxDriver or ChromeDriver everything seems to be ok. When I work with HtmlUnitDriver though things start to go wrong.
Here is a sample code:
WebDriver driver = new HtmlUnitDriver();
driver.get("http://localhost:8099/");
WebElement loginButton = driver.findElement(By.xpath("//button[#type='button']"));
loginButton.click();
i'v looked at the driver.getPageSource result, and the source code presented there is very partial.
it doesnt show me all the elements. it is the same a clicking view source on the page.
what i need from the driver is the entire source, like firebug or chrome inspector give me.
any ideas on how i can retrieve it?
my app was written with the GWT.
thanks a million
Have you tried to enable JavaScript for HtmlUnitDriver?
I believe that the HTMLUnitDriver emulates IE by default (link) and there are other questions related to clicking buttons with IE. Have you tried this?
// Press enter on the button
loginButton.sendKeys("\n");
Also, have you tried adding an ID to the element and using that to find the button?
Window.open javascript function is not working in Mozilla, but working in other browsers, here is what I have write.
<a href="javascript:window.open('../Terms.aspx','Terms','width=550,height=400')">
click here</a>
Actually what happened in Mozilla is popup is opened but parent window is blank with [object Window]
Please tell me What I am doing wrong?
Thanks
The script looks all right, what might be a problem is that you are running it in the URL. Use the click event instead.
Also, you can use the href and target attributes in the link to make it degrade gracefully. That way the link will at least open up the page even if Javascript is disabled in the browser:
<a href="../Terms.aspx" target="Terms" onclick="window.open(this.href,this.target,'width=550,height=400');return false;">
click here</a>
Try a generator.
Alternatively, you might want to try href="javascript: randomVar = window.open ...". The issue might be that the window.open function returns an ID, thus breaking the in-line JavaScript.
Is there a way to open a page in XHTML without using <a href="page.html" target="_blank"> that is standards compliant?
I'm not using frames, but there are some pages that I want to open in a new window instead of the current one.
You can use javascript's window.open() method. However this could easily be blocked by a pop-up blocker. Why do you not want to use the "_blank" target?
You can use something like this:
My Page
And then you run this jQuery:
$(document).ready(function() {
$('a[rel="external"]').attr('target', '_blank');
});
This will add the target="blank" to the links and make your HTML validate :)
Most pop-up blockers wont block a pop up that has been requested by the user e.g you click a link and it pops up a window. IF you add an onlick event to your link and a target, the desired effect will work even if JS is turned off although you don't want to use target="_blank"