Found 871 Articles for Automation Testing

Selenium WebDriver Error: AttributeError: 'list' object has no attribute 'click'

Debomita Bhattacharjee
Updated on 29-Jun-2021 08:00:14

4K+ Views

We can get the Selenium webdriver error: AttributeError: 'list' object has no attribute 'click' while working on a test. Let us see an example of code where we have encountered such an error.ExampleCode Implementationfrom selenium import webdriver driver = webdriver.Chrome(executable_path='../drivers/chromedriver') #implicit wait driver.implicitly_wait(0.5) #url launch driver.get("https://www.tutorialspoint.com/index.htm") #identify an element m = driver.find_elements_by_name('search') m.click() #browser quit driver.quit()OutputIn the above code, we have got the error as we have used find_elements_by_name instead of find_element_by_name to perform a click operation on a single element. The method find_elements_by_name returns a list of elements.Here, we want to perform click operation on an element, so the ... Read More

How to get Response Status Code with Selenium WebDriver?

Debomita Bhattacharjee
Updated on 29-Jun-2021 07:53:00

3K+ Views

We can get the Response status code with Selenium webdriver. While executing a test, we can verify the Response code obtained from a server. Some common HTTP Response codes are listed below −5XX means there is an issue on the server.4XX means that the server resource cannot be identified.3XX means the request has been redirected.2XX means the request executed successfully.An instance of the class HttpURLConnection is created to obtain the HTTP Response. To have a link to an URL, the method openConnection method is used. Then we have to use the method setRequestMethod and pass HEAD as a parameter.To have ... Read More

How to save as PDF on Chrome using Selenium

Debomita Bhattacharjee
Updated on 29-Jun-2021 07:49:43

8K+ Views

We can save a pdf file on Chrome using the Selenium webdriver. To download the pdf file in a specific location we have to take the help of the Options class.We shall create an object of this class and apply add_experimental_option on it. Then pass the values - prefs and the path where the pdf is to be downloaded as parameters to this method.Syntaxo = Options() o.add_experimental_option("prefs" , {"download.default_directory": "../downloads"} )ExampleCode Implementationfrom selenium import webdriver from selenium.webdriver.chrome.options import Options #object of Options o = Options() #path of downloaded pdf o.add_experimental_option("prefs", {"download.default_directory": "../downloads"}) #pass Option to driver driver = webdriver.Chrome(executable_path='../drivers/chromedriver', options=o) ... Read More

Get Started With Selenium and Python Automation

Debomita Bhattacharjee
Updated on 29-Jun-2021 07:47:13

446 Views

We can work on Selenium with Python bindings. To get started with Selenium and Python automation in Windows operating system, we need to follow the below steps −Step 1 − Navigate to the link https://www.python.org/downloads/ to download Python.Step 2 − Click on Download Python . Once it is done, the Python executable file should be downloaded in our system.Step 3 − Python installation landing page is launched once the executable file is clicked. Click on the Install Now button.Step 4 − Python gets downloaded in the below path −C:\Users\\AppData\Local\Programs\Python\PythonStep 5 − We need to set the path of the Python ... Read More

How To Use TestNG Framework For Creating Selenium Scripts?

Debomita Bhattacharjee
Updated on 29-Jun-2021 07:43:50

227 Views

We can use the TestNG framework for creating Selenium scripts. TestNG is a testing framework built for the usage of both the developers and testers. The steps to integrate TestNG with Selenium scripts are listed below −Step1 − Click on the Help menu from Eclipse. Then click on Eclipse Marketplace.Step 2 − In the Eclipse Marketplace pop-up, input TestNG within the Find field and click on Go. Then click on Install.Step 3 − Accept the license agreement radiobutton and then click on Finish.Step 4 − Click on the Restart Now button.Step5 − Click on the File menu, then click on ... Read More

How to Resize Browser Window in WebDriver?

Debomita Bhattacharjee
Updated on 29-Jun-2021 07:24:18

3K+ Views

We can resize the browser window in Selenium webdriver. We can configure the size of the browser with the help of the set_window_size method in Python.The dimensions of the window size are passed as parameters to this method. Again, to get the size of the browser, we can use the method get_window_size.Syntaxdriver.set_window_size(200, 500)ExampleCode Implementationfrom selenium import webdriver #set geckodriver.exe path driver = webdriver.Firefox(executable_path="C:\geckodriver.exe") #maximize browser driver.maximize_window() #launch URL driver.get("https://www.tutorialspoint.com/index.htm") #new browser size driver.set_window_size(800, 880) #get window size print(driver.get_window_size()) #close browser driver.close()OutputRead More

Open New Browser Tab in Selenuim

Debomita Bhattacharjee
Updated on 29-Jun-2021 07:21:04

500 Views

Answer − We can open a new browser tab in Selenium webdriver. The methods - Keys.chord and sendKeys are required to achieve this task. The Keys.chord method is used to send multiple keys at once.We shall pass Keys.CONTROL and Keys.ENTER as parameters to this method. The complete string is again passed as a parameter to the sendKeys. Finally, the method sendKeys shall be applied on the link which we want to open in a new tabSyntaxString l = Keys.chord(Keys.CONTROL, Keys.ENTER); driver.findElement(By.xpath("//*[text()='Links']")). sendKeys(l);Code Implementationimport org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; import org.openqa.selenium.firefox.FirefoxDriver; import java.util.concurrent.TimeUnit; import org.openqa.selenium.Keys; public class OpenNewTab{    public static ... Read More

Selenium CSS Selectors Examples

Debomita Bhattacharjee
Updated on 25-Jun-2021 16:21:19

655 Views

 We can locate elements with locator CSS Selector in Selenium webdriver. The general expression to create a CSS expression is tagname[attribute='value']. We can utilize the id and class attributes to create a CSS.With id, the syntax of a CSS expression is tagname#id. For instance, for a CSS expression - input#txt-loc, input is the tagname and the txt-loc is the value of the id attribute.With class name, the syntax of a CSS expression is tagname.class. For instance, for a CSS expression - input.txt-cls, input is the tagname and the txt-cls is the value of the class attribute.If there are n sub-elements(children) ... Read More

What are the various Components of Selenium?

Debomita Bhattacharjee
Updated on 25-Jun-2021 16:20:15

4K+ Views

There are various components of Selenium. It can work on multiple browsers like Chrome, Firefox, Safari, and so on. It also supports more than one operating system like Windows, Mac, Linux, and so on.The components of Selenium are listed below −Selenium IDE.Selenium RC.Selenium Webdriver.Selenium Grid.Selenium IDESelenium Integrated Development Environment is an important part of the Selenium suite. It was first developed as a Firefox plugin, however now it is available in both Firefox and Chrome browser.Some of the features of Selenium IDE −The recording, debugging and editing of the functional tests can be done in Selenium IDE.The scripts in Selenium ... Read More

Difference between find Element and find Elements in Selenium

Debomita Bhattacharjee
Updated on 25-Jun-2021 13:50:16

4K+ Views

There are differences between findElement and findElements method in Selenium webdriver. Both of them can be used to locate elements on a webpage. The findElement points to a single element, while the findElements method returns a list of matching elements.The return type of findElements is a list but the return type of findElement is a WebElement. If there is no matching element, a NoSuchElementException is thrown by the findElement, however an empty list is returned by the findElements method.A good usage of findElements method usage is counting the total number of images or accessing each of images by iterating with ... Read More

Advertisements