How to get the current URL in Robot framework? - selenium-webdriver

When the 'apply' link is clicked, it opens a new browser in Robot framework. How to get current url of that page? Here is the code:
Open Server
Set Browser Implicit Wait 60
Go To ${server}/jobs
Element Should Be Visible xpath=.//*[#id='txtjobsearch']
Input Text xpath=.//*[#id='txtjobsearch'] ${job Title search}
Element Should Contain xpath=(.//*[#class='clearfix tit-job']/div)[1] ${Job title}
Element Should Be Visible xpath=(.//*[#class='btn btn-sm btn-primary btnApply'])[1]
Click Element xpath=(.//*[#class='btn btn-sm btn-primary btnApply'])[1]
After this line, it opens a new window. How to get url of newly opened page and do actions like input text?
Set Browser Implicit Wait 20
Wait Until Page Contains Element xpath=.//*[#class='text-primary']

Try this:
${url}= Get Location

getting the current URL is easy using the Execute Javascript SeleniumLibrary keyword:
${url} = Execute Javascript return window.location.href;

Have you tried using the Select Window keyword?
http://rtomac.github.io/robotframework-selenium2library/doc/Selenium2Library.html#Select%20Window
Click Link popup_link # opens new window
Select Window popupName
Title Should Be Popup Title
Select Window # Chooses the main window again
It seems like you wish to verify the url of the new window which should be easily possible with the following:
Select Window | url=https://google.com
Obviously you need to replace the above url with what you're expecting. Let us know how you get on.

Related

Mouse hover text to be logged in report (Selenium)

I want to get the text from mouse hover on an element on a webpage and put it in log. I tried getText and getValue but they are not working.
I am using Selenium and robotframework.
I want to get:
This property can be modified in dt-site.xml located in the user home directory
from:
<i ng-if="!row.canSet" class="glyphicon glyphicon-info-sign ng-scope" tooltip-popup-delay="0" tooltip-placement="left" uib-tooltip="This property can be modified in dt-site.xml located in the user home directory."></i>
It looks like it is coming from the tooltip. You can try this:
String title = webElement.getAttribute("uib-tooltip");
If this does not work, then it could be because of angular magic. Tryu
String title = webElement.getAttribute("title");
The title attribute is what the browser reserves as the "popup" text.

Upload file using arrow mark in webdriver

I have to upload an excel file in the application.For that, I need to click on one arrow mark (i.e;browse button)which will open up the popup for the user to choose the file from local drives.Below is the code displayed when I did inspect element on the arrow mark.
" ".
Also, the path which will display after choosing the file will be greyed out before user selects the file. This will be enabled only when the user chooses some file from the local.
I was trying below code but it did not work. I think send keys is wrong option as the text path is greyed out.
Help me on this.
WebElement El = driver.findElement(By.id("'uploadInp'"));
driver.findElement(By.id("uploadInp")).click();
El.sendKeys("D:\\NTN 4\\Demo\\BulkCart_Template.xlsx");
Arrow HTML code:-
<input id="file1" type="file" value="" style="background-color: red;opacity:0;filter:alpha(opacity=0);cursor: pointer; padding-top:3px;width:25px;" name="file">
You do not need to click on browser button or open any pop-up. sendkeys will going to dump your path in HTML DOM for you
So don't click on browser button while use the same button element to perform sendkeys like below:-
WebElement El = driver.findElement(By.id("'uploadInp'"));
El.sendKeys("D:\\NTN 4\\Demo\\BulkCart_Template.xlsx");
Now you need to click on element which is going to start your upload. As you didn't mention and it's unclear according to your question that which element going to upload your file. Just find that element and click on it normally.
Hope it will help you :)

Open embedded Visualforce charts in new window

I have two embedded charts in a custom VF page that is then displayed on the Account detail screen. I'm passing the correct parameters and the reports work fine and display fine on the Account detail page.
<div class="col-md-6">
<analytics:reportChart reportId="00Oi0000005jhBz" cacheResults="true" size="medium" filter="[{column:'Order.Account.Id', operator:'equals', value:'{!Account.Id}'}]"></analytics:reportChart>
</div>
What I would like to do, however, is instead have a text link and those reports open up in a new window. Can embedded charts open in a new window and I pass the correct parameters via the URL?
I can get the reports to display in a new window fine, but I am unclear how to pass the correct filters in my link so the reports actually display the correct data:
<a href="/apex/getIndustryAccountReports?vID={!Account.ID}" target="_blank">
Are there certain ways I have to do this, so that the reports in the new window get passed the correct filters?
your Visualforce page can call on action
"init" would be a function on your controller like so:
public void init() {
String vid = ApexPages.currentPage.getParameters.get('vid');
}
You can now use "vid" to embed the report in your visualforce page.

strange Selenium2 No Such Element error

I have this HTML code.
`<div> <i class="icon-plus icon-white"></i>
<span>
<input type="file" multiple="multiple" name="uploadFile" value="Attach2" id="1309261001000145" style="visibility:hidden;position:absolute;top:0;left:0"> <input type="button" onclick="fireFileButton('1309261001000145')" value="Attach" name="input" class="btn_grn btn_sm">
</span>
</div>`
the div is in a normal nested divs. The second is the displayed 'attach file', once clicked, the "fireFileButton" function will click the first form(which is hidden on top left 0,0 position). then a pop up window appear as the type is 'file' to select file to upload and an ajax to upload.
I'm to use Selenium2 to simulate the file upload process.
I use the following codes:
WebElement attach = (new WebDriverWait(driver, 15)).until(ExpectedConditions.presenceOfElementLocated(By.cssSelector("//input[name^='input']")));
attach.click();
WebElement upload = (new WebDriverWait(driver, 15)).until(ExpectedConditions.presenceOfElementLocated(By.id("1309261001000145")));
upload.sendKeys("C:\\Users\\Public\\Pictures\\Sample Pictures\\Desert.jpg");
I also tried directly use sendKeys Function on first element. But have the error of NO SUCH ELEMENT both for first and second . I have used By.id,name,cssSelector,xpath but to no avail.
the elements can be selected using javascript.
Any Suggestion is much appreciated.
By.cssSelector("//input[name^='input']")
Selectors should not contain //,so replace the above with :
By.cssSelector("input[name='input']")
You can refer this to know more about Selectors.
First check : ID tag.
It seems that ID for the input buttons are dynamic. So we cant access through the ID's.
Second check : NAME tag.
We can use, since it has a name for it.
WebElement attach = driver.findElement(By.Name("input"));
attach.click();
If it is not clicking, use Actions.
Actions action = new Actions(driver);
action.moveToElement(attach).click().perform();
You cannot pass the values directly using sendkeys for file upload.
Check this page for my solution in order to access with file upload : How to handle Windows file browse window using selenium webdriver

How to browse and upload file through selenium Web driver

I am trying to upload a file through selenium webDriver but selenium gives an error:Unable to locate element. I have used all method to find element and click on browse but not any click occurring on that.
The HTML is <input type="file" onmousedown="this.blur();" onclick="//this.blur();" onchange="$('file-loader').show(); this.form.submit();" name="metadata_item" id="metadata_item">
First check the input element is visible
Then, you don't have to click on the browse button, it will trigger an OS level dialogue box and effectively stop your test dead.
In order to deal with this follow this code:
driver.findElement(By.id("myElementId")).sendKeys("<pathToFile>");
myElementId is the id of that element (button in this case) and in sendKeys you have to specify the absolute path of the content you want to upload. The Webdriver will do the rest for you.
Keep in mind that the upload will work only If the element you send a file should be in the form
cant answer without HTML code.
in order to click Browse button place the pointer in previous field i.e,
email address field and use
Robot robot=new Robot();
robot.keyPress(KeyEvent.VK_TAB);
robot.keyRelease(KeyEvent.VK_TAB);
robot.keyPress(KeyEvent.VK_ENTER);
robot.keyRelease(KeyEvent.VK_ENTER);
and then a system popup displays then use AutoIT tool to handle it
It could be under another frame.
Try switching to that frame and click the element.
It would work.
For Example - If the browse button is under another frame which has Id = "frameUpload", then switch the webdriver to that frame like this:
driver.switchTo().frame("frameUpload");
Now click on the browse button like this:
driver.findElement(By.Id("Id of the button")).click();
once you are done with the click, you can always get back to the default window like this
driver.switchTo().DefaultContent();

Resources