Work with second opened broser - selenium

I am new to selenium i have a problem with.
I am working with one form at that when I click the "Report" it
launches the new browser with some data. I want to work with data.
How to get that data and verify that data
Launching and opened browsers are Fire fox browser
Please share your experience.

Assuming this is Java you are talking about - using the getting started with selenium framework.. your test would look like this.
#Config(url="http://mysite.com", browser=Browsers.FIREFOX)
public class MyTest extends AutomationTest {
#Test
public void myTest() {
click(By.linkText("Report"))
.waitForWindow("The Report") // specify what title or url the window is to be
.click(By.linkText("something in the new window"))
.validatePresent(By.cssSelector("div#content")); // validate whatever you need.
}
}
If you are choosing to not use a framework, then you will have to use the WebDriver#switchTo()#window() method to switch to the window.
Also, disambiguate selenium-rc and selenium2. They are both completely different software packages.

This is with related to selenium rc
Consider the case where I have 2 forms or window:
Currently I am at 1st form where Report button is present when I click the button it opens another form or window.
Below code is to select the 2nd form or window and maximizing it...
Please give the title of the window..(in my exmaple i have title of 2nd form as 'Terms & Conditions | Photojaanic').
selenium.selectWindow("title=Terms & Conditions | Photojaanic");
selenium.windowFocus();
selenium.windowMaximize();
Below code is to return to original form where Report button is present.
selenium.selectWindow("null");
selenium.windowFocus();

Related

How to add text in pop up window in selenium

I am trying to test a website using selenium(with java). On my website, there is an option to add a new class. When we click on the add new option button, a pop-up window will come and we can enter our new class name. But using selenium I cannot enter alphabets into the pop-up window. I can only enter numbers in that field. The field accept both alphabets and numbers when we enter the data manually. How can I add alphabets to the pop window in selenium?
Here I attach my code below :
WebDriverWait wait = new WebDriverWait(driver, 20);
wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//*[#id=\"modal-add\"]")));
driver.findElement(By.xpath("//*[#id=\"class\"]")).sendKeys("LKG");
driver.findElement(By.xpath("/html/body/section/div/div[3]/div/div/form/div[2]/button[2]")).click
screenshot of the field - Class_field_screenshot
As mentioned above you are not able to add alphabets in textfield using sendkeys function. I haven't heard this type of issue before please confirm that either that field accept alphabets or not. if that feild accept alphabets then try using another way like javascript executor to send text as mentioned below
JavascriptExecutor js = (JavascriptExecutor) driver;
js.executeScript("$('#id').val("sendtext")");
Can you try Clipboard class for copy and paste string value in class field ? Make sure you click first in class text field and then use paste code. As you say by keyboard you are able to enter alphabet so try to use keys class too.In both cases your keyboard is going to use so may be it helps.

Not getting value from gettext()

I have used getText(); but not working please help me out
Text Box 1: I need to get the value from this text box.
String value = driver.findElement(By.xpath("html/body/div[5]/div/div/div/div/div[2]/div/div[1]/input")).getText();
Text Box 2: I wanted to put it here but value is not coming here.
driver.findElement(By.xpath("html/body/div[1]/div/div[2]/div/div/div/div[2]/div[1]/div[1]/form/div/input")).sendKeys(value);
Any help is appreciated, thanks in advance.
getText() is not working in many occasions. You can use .getAttribute("value") to get the text.
Make sure your first text box is not inside an iframe and is visible accessible. If it is, then its possible that your xpath might not be correct. Instead of using system generated paths or the full path , try using css and other locators to identify the element. What browser are you using ? IE is sometimes slow to respond to the sendkeys method. Use chrome instead and if that is not an option, try copy pasting using the below code
.sendKeys(Keys.CONTROL,"v");
public void copyToClipBoard(String data) {
// TODO Auto-generated method stub
Toolkit toolkit = Toolkit.getDefaultToolkit();
Clipboard clipboard = toolkit.getSystemClipboard();
StringSelection selectedData = new StringSelection(data);
clipboard.setContents(selectedData, null);
}

Tosca: How to scan Dropdown textbox which disapper upon opening xScan

I have a problem in scanning a drop-down menu which disappears upon opening the xScan. I need to get the module id of the dropdown menu to verify some test steps.
Do you have any solution with this if it is not really possible to get the module id of the dropdown menu?
Open developer tools in your browser of choice (F12), navigate to the console and input the following code:
var fulldoc='';
var scrollX=0;
var scrollY=0;
document.addEventListener("keydown",function(event){
if(event.key=='q' && event.altKey){
fulldoc=document.body.outerHTML;
scrollY=window.pageYOffset;
scrollX=window.pageXOffset;
}
if(event.key=='w' && event.altKey){
document.body.outerHTML=fulldoc;
document.body.scrollTo(scrollX,scrollY);
}
});
When the window looks the way you would want to scan, press 'Alt + Q', then press 'Alt + W'.
Now your window will freeze and then you can scan your page.
To steer the objects you need to refresh your browser.
You can resolve the issue with below 2 steps
1 - Add some text in textbox which will populate the dropdown below it .
2 - Use Send Keys Module to scroll down and select the value.
I had a similar issue where we had a popup that only appeared when clicking on a text box. The solution we received from the Tricentis trainer was as follows:
Part One
1. Open your application in Chrome
2. Right click the inspect
3. In the inspector window, on the Elements tab, navigate to your html element where it should be (you can do that by clicking on the element and check that you can see the html in the element)
4. Use the debugger to add a break point there, this should pause it and you should be able to see the elements you need to steer it.
5. Once you found the element, you will need the type of element (e.g. div, span, etc), and the class name
Part two
1. Rescan your module and select any element that matches the criteria of your element selected in Part One #5
2. Identify it by only it's class name property and tag
3. Save and close
4. Edit the element in the module view by changing the class name. This should help you steer it
Note: if the element class name is not unique, you might need to use Explicit name.
Good luck

3 searchbox with 3 question marks, Sikuli Fails to click 2nd element

I have 3 search box field and 3 question marks near by each search box. If I try to click on the 2nd question mark, It always clicks the 2nd Search box instead of clicking the question mark button. [Sikuli not clicking the exact element]1 Kindly have a look into the below image i have attached. Click "1" to view the image... Pls dont come up with coordinates. I shouldn't use coordinates in my project.
Well, this may not be the fully qualified answer, which do not use Region, Co-ordinates & autoIT as you are expecting.
This is code in Sikuli which uses findAll() method.
I created a dummy window as per your screenshot as below:
Edit
public void clickButton() throws AWTException, FindFailed
{
m_sikscr=new SikuliScript();
m_screen=new Screen();
m_sikscr.switchApp("Java Swing Examples");
m_screen.wait((double)3.0);
int i=0;
Match[] array=new Match[5];
Iterator<Match> rs1 = m_screen.findAll(new Pattern("./img/Button1.png"));
while(rs1.hasNext())
{
array[i]=rs1.next();
i++;
}
m_screen.click(array[1]);
}
This clicks only the second button on screen.
Hope this much triggers the thought of making it work completely.

seleniumIDE - how to store a hyperlinks address and then visit that URL? Was working before

I had this working fine a couple of months ago but now when I run the test it fails and I don't know why or how to fix.
Background:
I have a screen with several links so that the 'admin' user who is currently logged in can login as one of the 'practitioners' via the login hyperlink presented.
Details:
So for my test I click on the 'Login link' hyperlink(s), enter & confirm a new password as required, and then I get to the practitioners screen 'as them'. The 'wrinkle' was that the pop-up for the user to enter their (new) password happened on a new window that the selenium IDE used was a new window. So basically just clicking on the hyperlink didn't work. To get around this I was able to store the hyperlink's href -a#href- in a selenium variable first_login_link_to and then use open instead of clickAndWait to visit the page, i.e. open ${first_login_link_to}
This was working fine a few months ago.... but it is not working now.
I get page doesn't exist and when I look at the url - urgh! It somehow includes the locator stuff and I am getting
http://dmplanning-stage.herokuapp.com//tr[td[contains(.,'6 Day')]][1]/td[8]/a#href
instead of
http://dmplanning-stage.herokuapp.com/p/zaH7m3aL7fxuPLvrc21L
in the browsers url address bar.
How can I get selenium to open the url stored in the variable and not use that 'locator' address?
selenium:
open /admin
clickAndWait link=practitioners
store //tr[td[contains(.,'6 Day')]][1]/td[8]/a#href
open ${first_login_link_to}
Found it - whew! Somehow my storeAttribute got changed to plain store.
Once I changed it back everything worked again!
This one worked for me
1-
Command = Store
Target = stuff you want to paste
Value = Var
2-
Command = sendkeys
Target = id for area where u wana paste
Value = ${Var}
3-
Command = Fireevent
Target = id for area where u wanna paste
Value = paste