PageFactory error: incorrect amount of parameters provided (2 instead of 1)

Currently implementing the page factory pattern and encountering Argument errors in multiple locations.

  1. This is the code for my Homepage class:

     require 'page-object/page_factory'
     class Homepage
     include PageObject
     include Configuration
    
     def initialize(browser)
        @browser = browser
      end
    
      def open
     goto("url")
      end
    
      def sign_in
     @browser.element(css: 'div.links-static ul li.account div#login_user_data a.account').click
     end
    
      def create_account
     @browser.element(css: 'div.ml_function.ml_function_arrowtoptoleft.padding_top_twenty.height_fifty input.ml_function_button_createaccountRegister').click
      end
    end
    
  2. In the Given step:
    Given(/^I am on shopclues homepage$/) do
    visit(Homepage)
    end

  3. Scenario: User needs to create a new account
    Given I am on shopclues homepage ----> Error displayed at this point
    When I click on sign in
    And I fill the user information
    And I click Create Account
    Then I should see the user details

Answer №1

The issue arises from the redefinition of the initialize method within the page object.

When you include the PageObject module, an existing initialize method is already in place:

def initialize(root, visit=false)
  initialize_accessors if respond_to?(:initialize_accessors)
  initialize_browser(root)
  goto if visit && respond_to?(:goto)
  initialize_page if respond_to?(:initialize_page)

This default method can handle up to 2 arguments. By utilizing the visit method, your page object is initialized with 2 arguments. However, since you have customized your initialize method to only accept 1 argument, it causes an exception.

Unless there is a specific reason for this customization, it is recommended to remove the custom initialize, resulting in a simplified class definition:

class Homepage
  include PageObject
  include Configuration

  def open
    goto("url")
  end

  def sign_in
    @browser.element(css: 'div.links-static ul li.account div#login_user_data a.account').click
  end

  def create_account
    @browser.element(css: 'div.ml_function.ml_function_arrowtoptoleft.padding_top_twenty.height_fifty input.ml_function_button_createaccountRegister').click
  end 

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Learning how to extract information from an Excel spreadsheet by utilizing two @Test methods within a single class in TestNG Selenium WebDriver

Is it possible to have two @ test methods in one class and fetch data from an excel sheet for both @ test methods using the same excel sheet? Can two methods be used in the same class with one excel sheet containing data for both @ test methods? I am see ...

Guide on navigating the mouse pointer to an element using Selenium and nodejs

Currently, I am developing with nodejs and have incorporated the selenium module. However, I am facing an issue where I need to click on a button by moving the mouse pointer to the element location. Can someone please advise me on how to use ActionSequence ...

Explore the capabilities of Selenium Grid by using its API to view a comprehensive list of all

Is there an API method that allows for the listing and retrieval of information for all registered nodes on a Selenium Hub? I know I can use /grid/api/proxyid=nodeurl:5555 to obtain information about a specific node, but I'm struggling to find a way ...

Setting a Timeout using PageFactory in Selenium

When it comes to cleaning up page objects, I am well aware that using [FindsBy] attributes and PageFactory can be a useful approach. Defining properties in this manner can be done as shown below: [FindsBy(How = How.CssSelector, Using = "input[type='s ...

Having difficulty fetching the xpath from Science Magazine as it results in an empty list with no elements

Currently, I am working on a page that can be accessed through doi.org using the article code: 10.1126/science.aaa1442 I am attempting to extract the content within the address tag by utilizing the following xpath expression: //li[@class='aff'] ...

It appears that there is a security concern with your current connection while utilizing Selenium.WebDriver version 3.6.0 with Firefox version 56

While working on my tests using Selenium with C#, I encountered a major issue when testing my website with a secure connection (HTTPS). Unfortunately, all the solutions I found on stackoverflow were either outdated or ineffective. I attempted to implement ...

Is there a way to retrieve column values from an Excel spreadsheet by referencing only the column name?

Is there a way to read usernames from the first column and passwords from any column in an Excel sheet without specifying the exact column address? FileInputStream fs = new FileInputStream(strReadFile); Workbook wb = Workbook.getWorkbook(fs) ...

Utilizing Selenium webdriver to retrieve images from the internet

Currently, I am attempting to retrieve images from a website using the following code snippet: List <WebElement> listofItems = driver.findElements(By.cssSelector("div.heroThumbnails:nth-child(4) > div:nth-child(2) > div:nth-child(n)")); URL ...

Annotations can be used to group Python Selenium tests, similar to how TestNG is used in Java

I'm currently in the process of restructuring a collection of Selenium tests that I originally wrote in Python. Several years ago when I was working with Java, I utilized testNG to annotate and categorize the tests based on their purpose (such as Smok ...

Selenium throwing NoSuchElementException in IE7 browser

Having some trouble using Selenium on Internet Explorer 7 with InternetExplorerDriver on a Windows XP system. The code runs smoothly on Firefox, IE9, and even IE9 compatibility mode on Windows 7. Here is the HTML snippet: <HTML xml:lang="fr" xmlns="ht ...

Tips for identifying all input elements containing specific text on a webpage using Selenium

I am attempting to locate all input elements on a website that contain a specific keyword and then input text into them. An example would be this particular website where there are 2 input elements with the word "email". I can specify one, but strugglin ...

I am attempting to extract flair from posts in subreddits using basic bs4. Can you help me troubleshoot what is going wrong with my

I'm currently attempting to extract the flair from posts on a subreddit using bs4. If successful, I plan to utilize selenium for infinite scrolling to extract as many flairs as possible. The following is my code without infinite scrolling: import requ ...

Creating a TestNG custom exception that is triggered specifically during a timeout in execution

I've been attempting to capture the ThreadTimeOut Exception, but I'm having trouble catching it in my code. Here's what my code looks like: @Test(timeOut=2000) public void timoutCheck() throws Exception { try { while (true) { ...

Having trouble starting Chrome Browser using Selenium Remote WebDriver

Hello, I am currently exploring Selenium and attempting to launch Chrome using the Remote WebDriver. Below are the specific details of my operating environment: Operating System: Windows 10 Enterprise Java Version: 9.0.4 Selenium Standalone JAR: 3.5.3 Deve ...

Scraping data with Node.js using chrome-remote-interface

Struggling to scrape a website protected by Distil Networks, using selenium in Python has been unsuccessful for me. After some research, it seems that the site is able to detect Selenium usage through javascript. I attempted to use chrome-remote-interface ...

Retrieve fresh elements and extract them using Selenium in conjunction with HtmlUnitDriver

I am facing an issue while trying to crawl a website that contains both titles and comments. Initially, the page loads with 40 comments visible, but when I click on the "Load comments" button, another set of 40 comments appears, repeating this process. My ...

An exploration of effortlessly moving elements using webdriver.io - the power of

I have been attempting to utilize the drag and drop method in WebDriver.io, but I am encountering issues. I followed the example for drag & drop on this website: https://www.w3schools.com/html/html5_draganddrop.asp. This functionality is essential for ...

Obtain the title of a Youtube video with Selenium in C#

Hey there, I'm currently working on using C# Selenium to extract the title of a YouTube video. Unfortunately, the methods I've tried so far haven't been successful. I've already tested getting the text from other elements and it works f ...

A guide to resolving the ERR_TUNNEL_CONNECTION_FAILED proxy server error using the free-proxy service

After following a tutorial on consolidating all necessary modules for a customized selenium webdriver into a single class, I encountered persistent errors when implementing the code: Traceback (most recent call last): File "c:\Users\s1982& ...

ERB failing to interpret Ruby script

Hello, my index.html.erb file looks like this: <h1>Bookmarks</h1> t <% @books.each do |b| %> <div class="book"> e <div class="row"> s <div class="col-md-1"> t <p class="rank-this ...