New answers tagged

0

You can do it as; 1. Have a static driver inside the test class; static WebDriver driver = null; 2.Create a single @BeforeClass, which will initialize the driver to your desired browser, navigate to gmail and login. 3. Have @Test annotations for all the 4 cases. 4. Remove/comment out all other tags from those individual classes. Just have them as methods. ...


0

Might be your driver is not initialized in landingpage.gotoProfile(); Check in gotoProfile() method if driver is initialized, properly. Things you can try Pass the driver to gotoProfile() method, as shown below landingpage.gotoProfile(driver); and accepting argument in gotoProfile method as bellow public void gotoProfile(WebDriver driver) { // code ...


1

You can try using @BeforeSuite You have to group your test classes into a suite in the testng.xml and annotate the setup method in one of your test classes. This link provides a nice tutorial: http://examples.javacodegeeks.com/enterprise-java/testng/testng-beforesuite-example/


0

If it is available, id should always be your preferred method of location of elements. It is the fastest and most reliable lookup. driver.findElement(By.Id("edit-box-big"))


1

Answer in Short This is xapth .//[@id=\'nosession\']/form/div[1]/input Which means, the xpath is trying to find out an any html element on page, which has id as nosession. Inside the nosession element we have a form with multiple div tags in it and we are selecting first div[1]. Inside first div tag we are finding for input element.


0

You can use the ANT parallel task to achieve this parallelism. Following is the demo which shows how to execute testcases parallel with Selenium Grid and JUnit. Download the demo Download the selenium grid from [here][1] and extract it into some folder Now navigate to extracted folder through command prompt and type following command ant launch-hub ...


0

To perform the file upload using java, you can use java Robot class. With this class you can perform keyboard operation. Following is code for MAC - Hopefully it works for Ubuntu. public void upload(String fileLocation) throws Exception { // Create object of Robot class Robot robot = new Robot(); StringSelection stringSelection = new ...


0

Instead you should create Firefox profile in order to invoke it locally. Refer this : http://www.howtogeek.com/209320/how-to-set-up-and-use-multiple-profiles-user-accounts-in-firefox/ This should resolve your problem.


0

If I understood correctly, your website has authentication, it prompts the user name and password. you do not require to do anything with selenium. You have to add username and password in url for example, your url is driver.get("http://example.com") you have to write it in this way driver.get("http://username:password@example.com") This will bypass ...


1

try...except block will allow you to bypass the timeout. But if you need that you are doing it wrong. Check presence of element before you wait of it's visibility.


0

You need to specify how the browser level authentication box is coming up for starters. Is it a JS pop up or is it a modal window. Depending on this, you can use corresponding methods from Selenium - driver.switch_to.alert or driver.switch_to.window() methods- these are in python, but you have corresponding methods in Java also. Also, you can refer to this ...


0

This is actually a relatively simple programming exercise: what differs/matters here is how you implement it. The HAR specifications (linked to from your link) state that the response object will have a key-value pair of "status": [HTTP Status Code (200, 404, 500 etc.)] Their example is "status":200 The response object is a member of each object in the ...


1

You are trying to get array of elements in single element, so compiler throwing an exception. Try: package Learning_Selenium; import org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; import org.openqa.selenium.firefox.FirefoxDriver; public class Selenium_Class { public static void main(String[] args) ...


0

You can try following xpath //div[@class='text_overflow-1']/u/a driver.findElement(By.xpath("//div[@class='text_overflow-1']/u/a")).click();


0

You have written a wrong code for finding an password element Your code is - WebElement password = test1.findElement(By.ById.id("Passwd")); password.click(); password.sendKeys("tftctctc141414"); And it should be as - WebElement password = test1.findElement(By.id("Passwd")); password.click(); password.sendKeys("tftctctc141414"); Mistake - you are ...


0

You are using findElement method which will return single element but you are try to save it in the list. Your code should be WebElement a=driver.findElement(By.className("android.widget.EditText"));


1

Selenium cannot perform any operation apart from web elements, pdf can be tested with the help of java Apache API for pdf Go through this link https://pdfbox.apache.org/docs/1.8.10/javadocs/ to explore more about PDFbox API


1

You are using findElements method which will return the list of elements. Where you should use findElement method which return single webElement Your code should be WebElement element = driver.findElement(By.name("q"));


0

Just extract the class attribute of the element and create the xpath String headingClass = heading.getAttribute("class"); String headingPath = "//div[@class='"+ headingClass + "']" then use headingPath wherever you want.


0

driver.manage().timeouts().implicitlyWait(60, TimeUnit.SECONDS); is the correct and cleanest way of doing this in my experience. Call it once after instantiating the driver, and all subsequent calls will correctly wait for whatever timespan specified (60 seconds in this case) It is better to be generous in timeframes for explicit waits, as lower ...


1

Bootstrap a clean environment for each test to test in isolation. This might look like a lot of overhead, but is very needed if you want to parallel run your tests and not get flickering and possible untrusted tests. Personally I create a session GUID and then generate test data and store in it in a database with the GUID. Boot an environment and let it ...


1

You have to use driver.findElement(By.name("q")) instead of driver.findElements(By.name("q")) when searching for single web element.


1

You can download the said PDF using Selenium webdriver, however I don't think you can verify the contents of the PDF, because that is not possible as far as I know using Selenium webdriver alone. You can use Apache PDFBox to verify PDF contents- however it is a JAVA library. I am not sure whether you can combine PDFBox, along with Selenium and automate the ...


1

This is one of the basic Webdriver concepts. When you are searching for a single element- like a single button that has to be clicked on, you use the findElement( ) , along with a locator mechanism, to find that element. For example- WebElement ele1= driver.findElement(By.name("btn1")); or in Python ele1= driver.find_element_by_id('btn1') You use the ...


4

FindElements returns a collection of elements. What you need to do is use the singular "FindElement" to get a single instance of an element to work with. WebElement element = driver.findElement(By.name("q"));


0

By doing some heavy research, I was able to find the solution by using: wait.until(ExpectedConditions.presenceOfAllElementsLocatedBy(By.finder)); The key was to find all the elements present in the part where i was going to validate if it was available. This solved the Time out's error: As for the Element is no longer attached to the DOM, and the ...


0

This issue is mainly because script is not giving time to load page. You have to use Thread.sleep(ms) I have solved your problem and giving solution below. Solution : import java.util.concurrent.TimeUnit; import org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; import ...


0

use implicit wait to handle all kind of sync issues. driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS); user this at the time of declaring the web driver object; like: WebDriver driver = new FirefoxDriver(); driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS); driver.get("http://somedomain/url_that_delays_loading"); WebElement ...


0

There are 2 possibilities what is going on: some call of selenium functions will time out (click, type, etc.) after some time because the object is not there at all. even if you will enable the wait.until, this has its own timeout (could be 30 sec.) in selenium. Case 1) is solved by enabling waits before some click or other action should happen. To ...


1

We have to use SwitchTo() functions, to click an element on new window which opens from your original webDriver instance. Following code might work. public class AE_Shipment { public void AE_Shipment1() throws InterruptedException { MyClass1 M1= new MyClass1(); WebDriver w1 = M1.w; // get the current window handle String patentWindow = ...


0

I had faced a similar issue. Scrolling was enabled on the modal window, so I scrolled down and then tried to access the element. It worked for me.


1

I used a helper function to see if at least one element still exists. Because I'm finding a new element each loop, StaleElementException doesn't occur anymore. while(isElementVisible(d, (By.ClassName("search-choice-close")))) { d.FindElement(By.ClassName("search-choice-close")).Click(); ...


0

Just you are traversing through all the window handles using a for loop. First print the parent window handle. System.out.println(w1.getWindowHandle()); Take all window handles use toArray() to convert to Object[] a array. Object[] a=w1.getWindowHandles().toArray(); Then print the window handles of all the windows opened using for loop. for(int ...


0

There is something wrong with the way you have mentioned your code. You've mentioned that your element is in new window-I am assuming the waiting needs to be done once you have switched the window. So you need to place the wait condition after your window handling code- String parentHandle = w1.getWindowHandle(); // get the current window handle ...


0

This is possible using the cookies concept of selenium webdriver. Please refer the below code public class SessionRestoring { public WebDriver driver; @Test public void test() throws InterruptedException{ driver=new FirefoxDriver(); driver.manage().window().maximize(); driver.manage().timeouts().implicitlyWait(10, ...


0

This happened because Selenium script was not able to find the element in the time duration mentioned. This happens when your page is not loaded inside the time frame that Selenium has set for locating elements. The best approach to handle this is to use the waits( ). You can use either implicit or explicit wait- the latter is preferable. eg- If you use ...


2

As I understood the question, it is required to define the reusable methods and use those methods in different test cases based on the requirement. Here I am writing the code for two individual methods to work with,... public void inputKeys(WebElement we,String ip){ we.sendKeys(ip); } The above code just type the string value referred by ip variable. ...


0

Just replace the findElement () method with findElement**s**(plural). Since the findElement method always returns a WebElement instead of a List of WebElements. The findElements method will return the list of webelements, which can be referred by a variable of type List<Webelement>. So the line of code will looks like,.. `List<WebElement> ...


0

Since they have already given you the test scenario and have told you what they want asserting ("verify that total price matches"), it looks like they really just want to see your coding style and how you would design the DSL for this scenario. I think the way you have split up the packages sounds sensible. Not sure what they want specifically but if it ...


1

This worked for me in webdriver.io var webdriverio = require('webdriverjs-angular'); var options = { desiredCapabilities: { browserName: 'firefox' }, ngRoot: 'html' // main application selector }; var wd = webdriverio.remote(options).init(); var wd2 = webdriverio.remote(options); ...


2

The getText() method returns all the text within a HTML element. In this case all the text between the start <a> and the end </a>. This includes other tags and their contents. Try to split the string on white spaces and use the first word found. String value = getText(); String[] words = value.split("\\s+"); String result = words[0]; Now ...


0

Since the text Logout is what exactly we are looking for then no need to write text contains. You use below xpath. (By.xpath("//div[.='Logout']"));


-1

you should use Java String Substring and not string trim,trim removes only trailing and leading spaces


1

Certifications don't teach testing. Still if you want to go for one, well, there are several available out there. But, they don't teach you how to test, they mostly teach only a certain terminologies. Yes, learning a programming language is an added advantage for a tester, especially for someone who is looking to make a career in automation testing or ...


1

The question and the description that you have written for it are misleading. I'm assuming you want to know which certifications will help you get a start for your career in Software Testing. Well for that I don't think you need to go for any certifications. Read good blogs and article on testing. There are thousands of them available on the internet. ...


10

I don't know whether a certification is necessary for automation testing, but you definitely require good coding skills and logic development skills for it. Its advantageous to learn Java as its open source and hence there are countless forums and communities to seek kelp. Plus many of the automation testing tools (specially open source testing tools) use ...


1

Everything enclosed within the <a> </a> tags is considered as part of the link text. So if you use the getText() method of Selenium, you will get the whole text. If you want a part of the text, you should try to shed the unwanted text. Get the text and store it in a String variable. Trim the unwanted text from that string and you will have ...


6

If you want to do it manually, then you will have to trace the path from the root of the host up to where the element is being generated. OR There is an easy way to get the xpath. In Mozilla FireFox install Firebug addon. Then install Firepath addon. Now visit your web page. Press F12 to open Firebug console. Click on the Firepath tab. Inspect the element ...


1

Python is widely considered as best language for beginner programmers. Java puts more focus on generating fast code (which adds requirements on programmer). Python is substantially more forgiving, and for website testing, speed is not the first requirement (flexibility is, where Python shines). Also, if you want to be programmer, you need to improve your ...


1

Actually java or other languages could be good option to drive Selenium tests, but it is not a must. You can command WebDriver from many different languages. Ruby, java, C#, VBA, VBS, javascript. Thanx to WebDriver you will have possibility to run your tests in multiple browsers (Chrome, Firefox, IE, Safari...). But all the languages are just a plus. If ...



Top 50 recent answers are included