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']")));
Related
I am attempting to write automation tests for the front-end UI of an app , that has a lot of nested shadow-doms and I am unable to access them using the Capybara, Cucumber & Selenium (using chromedriver). The app is using AWS Amplify Authenticator . I keep getting the following error when I try to find an input element :
Unable to find css "input[id$='username']" (Capybara::ElementNotFound)
This is what my test looks like:
When('I type into the username field my {string}') do |string| find("input[id$='username']").set(string) end
I have read on other posts that chrome driver supports shadow-doms but not sure how it would be handled in this scenario
Currently you need to use evaluate_script to get access to the shadow-dom - like
element = find(...) # find element that contains shadow dom
shadow_root = #session.evaluate_script(<<~JS, element)
(function(root){
return root.shadowRoot;
})(arguments[0])
JS
shadow_root.find("input[id$='username']")
and then you can only use CSS based finders/actions/etc on the shadow DOM.
The WebDriver spec has been updated to bring more support for the shadow dom but it's not implemented in drivers yet - https://w3c.github.io/webdriver/#shadow-root
I am new to Angular & Protractor (and web development for that matter), so I apologize of this is an obvious question.
I am trying to test our angular app with protractor, and it appears that I can locate the first element on the page. But cannot find any of the other elements using (id, name, model, css). I have tried chaining off of the first element, but always get the element not found error on the second element in the chain. I've have triple check the spelling so I am confident everything is correct.
Our page is setup up with multiple sections and when I "view source" I only see the root div.
<head>
</head>
<body>
<div ng-app="app" id="wrap">
<div ui-view></div>
</div>
</body>
</html>
But when I inspect the elements using the developer tools (F12), they exist in the DOM, I just don't know how to get to them.
<input type="text" class="form-control ng-valid ng-dirty ng-valid-parse ng-touched" data-ng-model="vm.searchText" id="searchText" placeholder="(Account # / Name / Nickname / Phone #)">
I tried to access the control listed above using the following:
browser.element(by.id("searchText").sendKeys("test");
browser.element(by.model("vm.searchText").sendKeys("test");
element(by.id("searchText").sendKeys("test");
element(by.model("vm.searchText").sendKeys("test");
I also create a single button and used partialButtonText & buttonText, neither of which worked.
I also tried to add some async functionality with "then" but that didn't work either. How do I access these elements are are not contained in a single html file?
thanks.....
If an element is not visible, I believe protractor isnt able to interact with it. It can't click or get text or anything if it is not visible, that is actually checked before it can perform the action.
What you can do is check the element is present to ensure it is somewhere on the html.
var searchText = $('#searchText');
expect(searchText.isPresent()).toBeTruthy('Search Text element not present');
This will find an element with a css selector of id searchText, and then check if it is present(exists on the html).
If you want to interact with it, remember that protractor looks around like a human would. If a human cant click it, neither can protractor! Make sure it is on the page and visible.
Don't have the reputation points to add this in the comments to user2020347's response so...When you say not in "view source" I assume you're talking about dynamically generated content. Instead of using view source either use chrome or firefox developer tools to make sure you're using the right locators.
For example in chrome's console the following should return a result once the page is loaded:
$$('#searchText')
$$('input[data-ng-model="vm.searchText"]')
It also looks like you're sending keys to the same element.
Since you have an angular app protractor should wait for all elements to load, but just in case you might want to wait for the element to be present and/or visible on the page.
Same happened to me, because Protractor executed on the original (first) tab.
Try to switch between the tabs before accessing the elements:
browser.getAllWindowHandles().then(function (handles) {
browser.driver.switchTo().window(handles[1]);
});
I'm a backpacker and a programmer, trying to use the second skill to find openings in a full campsite. Rather than crawling fro scratch, I'm using the end-to-end testing framework nightwatch.js to navigate for me.
I've hit a roadblock, because nightwatch is having difficulty finding a specific element using css selectors.
Here are the elements and page:
Here is my test code:
Previous Attempts
My test code will click on the selection box with #permitTypeId. It will see that #permitTypeId option is visible. It will not see or click on any of the options when more specific values are specified. The five .click()'s are all css selectors I've already tried. None of the options are set to display:hidden or display:none. I have also tried all of the above without the .waitForElementToBeVisible() just in-case the waiting causes the dropdown to hide.
I've successfully clicked options from different dropdown menus on this website without any problem. Just this one is causing a headache.
The tests are running with the most current Selenium server and Firefox on Mac Yosemite.
tl;dr
Nightwatch.js/Selenium won't click on something from a dropdown menu.
The Path...
Cory got me thinking about jQuery and native DOM manipulation. Tried going that route and was successful selecting the correct option using Selenium's .execute() function:
.execute('document.getElementById("permitTypeId").options[1].selected=true')
However, it was not triggering the onchange event.
Saw this post which made me start thinking about using key-strokes and this one which suggested using arrow-keys to navigate down a <select> element to the option, then hitting enter.
...to the Solution
.click('select[id=permitTypeId]')
.keys(['\uE015', '\uE006'])
I've found that this is an issue with Firefox. Chrome and PhantomJS operate well clicking <option> tags.
you should be able to click like this way
browser.click('select[id="permitTypeId"] option[value="1451140610"]')
Additionally I was able to add a .click event for the specific option once I did a .click for the select. see my example below:
.click('select[name="timezone"]')
.pause(1000)
.click('option[value="America/Chicago"]') //selects the option but doesn't click
.pause(5000)
.keys(['\uE006']) //hits the enter key.
another solution:
.click('select[id="permitTypeId"]')
.waitForElementVisible("option[value='1451140610']")
.click("option[value='1451140610']")
Very simple way is to use .setValue('#element', 'value of option')
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();
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?