New answers tagged

1

Using priority to drive order of execution is perfectly fine, but question is why do you want to execute test cases in certain order? As a general rule test case should be atomic and should not be dependent on another test cases. In such case do you worry about order of execution. I rather don't pay much attention to order of execution unless its an explicit ...


4

Check below are the various methods to scroll your page up & down. Scroll Down: import org.openqa.selenium.JavascriptExecutor; WebDriver driver = new FirefoxDriver(); JavascriptExecutor jse = (JavascriptExecutor)driver; jse.executeScript("scroll(0, 250)"); //y value '250' can be altered Scroll up: JavascriptExecutor jse = (JavascriptExecutor)driver; ...


0

why don't you check normal http response. That will also work for a normal http page. Here is the code sample that you can use. @Test public void sampleTest(){ //test method //your code boolean abletoOpenPDF=linkResponse(driver.getCurrentUrl()); } public static boolean linkResponse(String url){ try { ...


1

If you do not mind about random values, for email you can use javascript to generate valid email anytime the TestCase runs including runs in different browsers. Example (you can modify or change the script): javascript{ /*random email*/ var chars = 'abcdefghijklmnopqrstuvwxyz'; ...


0

From your picture, I guess that you just enter the text and still not Save, so it is not updated and you cannot get it. --> Try to save it, then open it again, I think you can get the text easily. If the text already Save, try to inspect element and search "Administrator" text to see where it is.


2

So what you are trying to do is have a script run on different browsers and want to register a user with a unique email address. Well, Google allows you to use single email address for such testing purposes with incremental characters appended to your ID. How this works is, You have a Gmail account say example@gmail.com. You can use this same account for ...


2

My recommendation is that you store the state of what has been used within a test. So the test would initially create a new user with a unique email. You can use some random character generation or a database sequence to make each one unique. Personally I recommend using sequences as they are more deterministic than random characters and less likely to ...


0

Use following code: WebElement firstName = driver.findElement(By.xpath("//input[@name='firstName']")); String value = firstName.getText(); System.out.println(value);


0

Basically the problem seems like, the attribute "value" is not updating automatically, so after entering the text into textbox click somewhere else on the page and then use the method getAttribute("value") hope it will works......


0

It would help to check for other javascript attributes if getText is not working. How about if you try: el.getAttribute("innerHTML"); If that does not work, double check the element you are getting the text from. Are there any children elements for the input element?


0

When are you trying to get a value? before entering or after entering it in the text field? WebElement fName=driver.findElement(By.name("firstName")); fName.sendKeys("Admin"); System.out.println(fName.getText()); Above code should return text entered.


2

The reason behind the exception you have mentioned is because with your test script you are trying to locate an element that doesn't exist in the webpage you are trying to test. how will you resolve It? Well, along with the text you have provided, the console would also have given the line number in the test script where this exception occurred. I ...


3

You will get this exception when WebDriver Is not able to locate element on the page of software web application using whatever locator you have used In your test. To resolved this Issue, I will check bellow given things. First of all I will check that I have placed Implicit wait code In my test or not. If you have not placed Implicit timeout In your test ...


3

1: Select Cdropdown = new Select(driver.findElement(By.xpath("//select[@id='ClientId']"))); Cdropdown.selectByVisibleText("centralpen-ak-01"); driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS); Select Edropdown = new Select(driver.findElement(By.xpath("//select[@id='EnvironmentId']"))); Edropdown.selectByIndex(0); ...


1

adding Thread.sleep(3000) is not a good way to handle synchronization, rather use implicit wait. driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS); Implicit wait allows your browser to wait until element is visible or until time set by you, whichever is earlier.


10

Do you think that time is the problem here? If so try to increase the time you are providing in Thread.sleep(); and see it that works out for you. If its not the time, then did you try to find out what the problem is? Are you getting any error?


0

I just upgraded my selenium to 2.53 and upgraded to Firefox latest 46.0.1 and everything started working fine with relative xpath.


1

The silence is deafening :-) I have no personal experience with NightWatch, but I do have experience with the quirky nature of JavaScript, and because of that experience prefer Python, especially for big projects. Why you never ever reprogram working code from scratch - with history of failures cause by reprogramming from scratch. So if your company is ...


3

Major difference in TestNG and JUnit test frameworks is their scope. Junit is a unit testing framework while TestNG addresses testing at a higher level. and my recommendation is TestNG(Next Generation) Framework. Find the some references to get details about both of them- http://www.slideshare.net/ssuser220b38/junit-and-testng ...


6

JUnit 4 and TestNG are both very popular unit test framework in Java. However, TestNG's goal is much wider, which includes not only unit testing, but also support of integration and acceptance testing, etc. Which one is better or more suitable depends on use contexts and requirements. Annotations: In JUnit, the @BeforeClass and @AfterClass methods have to ...


2

It's simple, just you have to use Select method in WebDriver. WebElement countrydropdown=driver.findElement(By.id("country_id")); Select country=new Select(countrydropdown); country.selectByVisibleText("India (+91)");


0

Solution 1 : You are putting extra brackets for this. So remove it: //input[starts-with(@type,'text')][contains(@name,'login')] Solution 2 : You have to use conditions for xpath. //input[starts-with(@type,'text') and contains(@name,'login')] Please let me know If any query.


1

Here is change that I have made in your code- are they 2 different textboxes or single one? If you add screenshot of your textboxes it will clear to all of us- WebElement nameTbox= driver.findElement(By.xpath("//input[starts-with(@type,'text')][contains(@name,'name73652d80')])]")); nameTbox.sendKeys("maheshwagh27");


0

Use the below code: WebElement countryUL= driver.findElement(By.xpath("//[@id='country_id']/ul")); List<WebElement> countriesList=countryUL.findElements(By.tagName("li")); for (WebElement li : countriesList) { if (li.getText().equals("India (+91")) { li.click(); } }


0

Did you try looking at the second xpath in firepath? It is a possibility that with the second xpath there are more than one element present on the screen and that's why your webdriver is not able to find the xpath. I guess the first one will be failing and the second should be passing because you are using @name, 'name' in first but the @name,'login' in ...


1

You can use the below code: List<String> handles = (List<String>) driver.getWindowHandles(); // Switch to the third window. driver.switchTo().window(handles .get(2)); // Close this window driver.close()


0

Open Mozilla FireFox. Install Firebug add-on. Install FirePath add-on. Browse your webpage in FireFox. Hit F12. Click FirePath tab. Inspect the element for which you want to get the Xpath. Copy the xpath from the FirePath console. It's really this simple!!!


2

You may use this- Xpath1= //a[contains(.,'Create a Rediffmail account')] OR Xpath2=//a[contains(@href,'details')] OR Xpath3=.//*[@id='toprightinfo']/a[2] Or you try with other Locator types as- LinkText Check I have tried & found 1 match xpath-


5

Launching Safari browser is very easy, just you have to add safariDriver jar in your Windows Safari browser. Check after installation whether this icon is displayed or not? If Yes then it will work. Steps- Requirements: Safari Browser installed Selenium WebDriver Now we have to install SafariDriver extension with below steps. Manually install the latest ...


5

Page Factory Pattern is like an extension to Page Object Model , but Page Factory is much enhanced model. To start with, we just need to import package org.openqa.selenium.support.PageFactory "Factory class can be used to make using Page Objects simpler and easier". We use Page Factory pattern to initialize web elements which are defined in Page Objects. ...


2

There is another tool to record page object model. below is the link: http://seleniumrecorder.blogspot.com/


1

To switch between windows there are multiple ways to do it. This is what we are using: public void switchToNewWindow(int windowNumber) { Set < String > s = driver.getWindowHandles(); Iterator < String > ite = s.iterator(); int i = 1; while (ite.hasNext() && i < 10) { String popupHandle = ...


-1

Resolved. Quite a newbie error. I should use only firebug to find xPath. Like below [FindsBy(How = How.XPath, Using = ...


0

For testing Xpaths and CssSelectors, please open Chrome and its Developer Tools (by pressing F12). In the console screen, you can enter the following: $x("your xpath here") or $$("your Css selector here") After pressing Enter, the console will list all elements matching your query. This is the easiest method to test and fix any mistakes in your ...


1

You cannot do that with just Selenium, as @Peter-Masiar mentioned, but you can look at the Structural Similarity method. Additional link. My company has been using this method quite a lot for testing.


0

If the id is changing dynamically for a particular xpath then we can use the below xpath functions: contains : xpath Syntax: //html tag[contains(text()/@attribute, 'Expected Value')] Following-Siblings: Xpath Syntax : //html tag/following-siblings::html tag e.g : //img[@src = 'image2.jpg']/following-siblings::input[@type = 'button'] Preceding-Siblings : ...


2

I haven't tried it but there's a Chrome Extension called Selenium Page Object Generator that looks like it automates PO creation, and it supports C#. SWD Page Recorder also automates PO creation, and supports C#.


1

My current Solution. Parses through the HTML file (C:\QA\Test.html), finds all input tags and Select tags, if they have an ID it will convert them into a POM based format. It then prints out to C:\QA\Pom.txt the basic object for it. Overall, it does 90% of the work that I need, with minor editing. using System; using System.Linq; using System.IO; using ...


1

One non-selenium tool we use (we use the paid version) is GhostInspector which has several options for screenshots including comparing by % difference and by css selectors to target areas.


0

One option for verifying images is to use Applitools + Selenium. It seems to be gaining in popularity among the Selenium crowd as it's not just able to do image comparison but also do layout comparisons. I haven't used it myself but it's on my TODO list. From the looks of it, they have a decent tutorial where you can choose your environment (Selenium) and ...


3

At this situation We have lots of options- Option 1 : Look for any other attribute which Is not changing every time In that div node like name, class etc. So If this div node has class attribute then we can write xpath as bellow. //div[@class='post-body entry-content']/div[1]/form[1]/input[1] Option 2 : We can use absolute xpath(full xpath) where you ...


1

Use Sikulix API. Sikuli is a library that will help you compare two images or recognize images when they are displayed on your screen. After the said image is displayed, you can click on the recognized image. Download Link: http://www.sikulix.com/ Go for the download link: https://launchpad.net/sikuli/sikulix/1.1.0 Download sikulix-setup-1.1.0.jar Run ...


3

Selenium is a software library to locate elements on web page and interact with them. To deal with images, you need to use different library. Selenium can provide screenshots (images) but you need to use something else to work with such images. As a programmer, you need to master more than a single library, and learn to use right tool for the job.


1

You can calculate hash of images and then compare the hashes for equality. SO has a question on calculating hash


0

Check this code might work import java.awt.image.BufferedImage; import java.awt.image.DataBuffer; import java.io.File; import java.io.IOException; import java.util.concurrent.TimeUnit; import javax.imageio.ImageIO; import org.apache.commons.io.FileUtils; import org.openqa.selenium.OutputType; import org.openqa.selenium.TakesScreenshot; import ...


2

Use contains() or starts-with() function in xpah : Solution : With contains : //div[contains(@id,'post-body')]/div[1]/form[1]/input[1] With starts-with : //div[starts-with(@id,'post-body')]/div[1]/form[1]/input[1] Let me know If any query.


0

Use this xpath: //div[@class='ViewMenu' and text() = 'Videos'] because class selectedViewMenu is probably only when element is selected.


1

WebElement element=driver.findElement(By.xpath("(//div[@class='selectItemText'])[2]")); Thread.sleep(5000); element.click(); Thread.sleep(10000); driver.findElement(By.xpath("(//nobr[text( )='MDialog'])[4]")).click(); //driver.findElement(By.xpath("//nobr[text()='MDialog']")).click(); ...


0

First of all Select is not working with Div or any other element. Select are use only with element is having Select tag and inside it, only having option tags. Solution : WebElement element=driver.findElement(By.xpath("//div[contains(@id,'isc_FX')]")); element.click(); driver.findElement(By.xpath("//*[text()='MDialog']")).click(); Try this. ...


1

Javascript support for webdriver is pretty rough, so here's an example of this in Javascript, in case you're like me and need to go spend another half hour digging through documentation to find the right method names in JS: let profile = new firefox.Profile(); profile.setPreference('network.automatic-ntlm-auth.trusted-uris', '.company.com') let options = ...



Top 50 recent answers are included