I am using selenium to automate web gui tests. I would like to know, if selenium can return html which contains rendered html as a result of some button click?
For example, initial html has <div id="errorSection"></div>. Now, selenium clicks on a button and errorSection div tag is filled up like this:
<div id="errorSection">
<ol>
<li>Password must be 8 characters long</li>
<li>Username has already been taken</li>
</ol>
</div>
Is selenium able to send back rendered html with rendered content?
Related
I am using the following code to upload files to a website to a 'file' type element.
The code works fine in Firefox, Chrome and Safari.
However when I run the code against Edge the file is NOT uploaded
driver.setFileDetector(new LocalFileDetector());
selectFile.sendKeys(path);
This error is reported:
The command failed because the specified element is not pointer or keyboard interactable.
If I try using Javascript like this:
document.getElementById('manual_file_selection').sendKeys(path)
I get this: Object doesn't support property or method 'sendKeys'
As stated the same code works fine in Chrome, Firefox and Safari so I don't understand it.
This is the code behind the file upload button:
<div class="jsx-parser">
<div data-xxxxx-element="manual-file-selection">
<div class="button__container">
<label for="manual_file_selection" class="button button--primary" data-dragging="false" data-xxxxx-element="manual-file-selection--label">
<input id="manual_file_selection" type="file" accept="image/jpeg,image/png" data-xxxxx-element="manual-file-selection--input">
<span>Select File</span>
</label>
</div>
</div>
</div>
Anyone had any success uploading files to Edge with Selenium or is it not supported?
Based on your error messages, I'd give some Javascript a try. It's a bit hacky, as we execute JS to reveal the hidden input element, then send keys to it, but I've had success in the past.
// fetch the element
WebElement input = driver.findElement(By.XPath("//input[#type='file']"));
// run JS to reveal the element
JavascriptExecutor executor = (JavaScriptExecutor)driver;
executor.executeScript("arguments[0].style.display = 'block';", input);
// send file path keys
input.sendKeys(path);
It's worth a try. Let me know if this helps at all.
I am trying to get XPath in selenium webdriver for logout button of a webpage.
here's the a ref tag
<i class="fa fa-sign-out icon-2x"></i> Logout
can you help
As per the HTML you have shared to click the Logout button you can use either of the following line of code :
Java - cssSelector
driver.findElement(By.cssSelector("a.topnavlink[href='https://www.freecrm.com/index.cfm?logout=1'] > i.fa.fa-sign-out.icon-2x")).click();
Java - xpath
driver.findElement(By.xpath("//a[#class='topnavlink' and contains(#href,'https://www.freecrm.com/index.cfm?logout=1')]/i[#class='fa fa-sign-out icon-2x']")).click();
I would get it this way:
//a[contains(#href, 'logout')]
Or better, use css selector:
a[href*=logout]
I'm trying to click on button(which I marked in yellow) using xpath, but it is failing to click and more over no selenium exception found. I tried to click with css selector and ID. Using isdisplayed() - output is true. but with isselected() - output is false.
I Kept Webdriver wait (Visibility, element located, element to be clickable), implicit wait and explicit wait. But nothing is working out.
I'm new to selenium, please help me out
Below are the code
<button id="addNewButton-btnEl" class="x-btn-center" type="button" hidefocus="true" role="button" autocomplete="off" style="height: 19px;">
The developers on my team have implemented some tags to support capybara and automated tests. I want to use the same tags for Selenium Webriver. The element I want to locate is typically defined as follows:
<label for="manntallsSok:manntallsSokForm:tabView:ssn">Fødselsnummer</label>
<input id="manntallsSok:manntallsSokForm:tabView:ssn" class="ui- inputfield ui-inputmask ui-widget ui-state-default ui-corner-all form-control focusable"
type="text" aria-required="true" data-aft="fodselsnummer" name="manntallsSok:manntallsSokForm:tabView:ssn" role="textbox" aria-disabled="false"
aria-readonly="false">
The hooks the developers hava made is typicaly:
data-aft="fodselsnummer"
Is it possible to use this hook/tag in a selenium locateElement?
You can use it in XPath selector as below:
//input[#data-aft="fodselsnummer"]
if it is data-tag then prefer using CSS Ex : input[data-aft="fodselsnummer"]
This question already has an answer here:
Closed 10 years ago.
Possible Duplicate:
How to upload a file from a site using Selenium's java inteface
I am new to Selenium.Can you please tel me how to automate file upload in Internet Explorer using Selenium?
It is not easy, and it is not easy for very good reasons - security. If you are able to upload something like this, what's stopping someone uploading your details using the same method?
You have also given us no example to work with so:
Given this sample webpage:
<html>
<head>
<style type="text/css">
.fileSave { color: red; }
</style>
</head>
<label for="fileUpload">File location:
<input type="file" id="fileUpload" />
<br>
<br>
Save file
</body>
</html>
I can do this, in C#:
Driver = new ChromeDriver();
var fileUploadControl = Driver.FindElement(By.Id("fileUpload"));
fileUploadControl.SendKeys("C:\File.txt");
var submitLink = Driver.FindElement(By.ClassName("fileSave"));
submitLink.Click();
This has been asked several times and is also in some Selenium FAQ.
Selenium 2 (WebDriver) Java example:
// assuming driver is a healthy WebDriver instance
WebElement fileInput = driver.findElement(By.xpath("//input[#type='file']"));
fileInput.sendKeys("C:/path/to/file.jpg");
For Selenium RC, see this question.
The idea is to directly send the absolute path to the file to an element which you would usually click at to get the modal window - that is <input type='file' /> element.