mardi 16 juin 2020

How to fix TypeError raised raised - 'find_element() argument after * must be an iterable, not function' when trying to find an element using Selenium

I am learning to implement the Page Object Model in Python+Selenium, but getting this below TypeError for one of my project : "TypeError: find_element() argument after * must be an iterable, not function". Please find the code below in which I'm getting this issue and help me.

from selenium.webdriver.common.by import By
from pageObjectsFiles.ProductSelectionPage import ProductSelection
class ProductCategorySelection:
    def __init__(self, driver):
        self.driver = driver

    productCategorySelection = (By.XPATH,"//ul[@class = 'ac-gn-list']/li[4]")

    def productCategorySelection(self):
        self.driver.find_element(*ProductCategorySelection.productCategorySelection).click()
        productSelection = ProductSelection(self.driver)
        return productSelection

Trying to access the above 'productCategorySelection' in Test Class through below code :

from common_utilities.BaseClass import BaseClass
from pageObjectsFiles.ProductCategorySelectionPage import ProductCategorySelection
class TestiPhone11(BaseClass):
    def test_E2E(self):
        prodcutcategoryselection = ProductCategorySelection(self.driver)
        productselection = prodcutcategoryselection.productCategorySelection()

But, Getting this below error:

    def test_E2E(self):
        prodcutcategoryselection = ProductCategorySelection(self.driver)
>       productselection = prodcutcategoryselection.productCategorySelection()

test_iPhone11POM.py:8: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

self = <pageObjectsFiles.ProductCategorySelectionPage.ProductCategorySelection object at 0x03F133B8>

    def productCategorySelection(self):
>       self.driver.find_element(*ProductCategorySelection.productCategorySelection).click()
E       TypeError: find_element() argument after * must be an iterable, not function

..\..\..\pageObjectsFiles\ProductCategorySelectionPage.py:13: TypeError

Assertion failed

Assertion failed

Aucun commentaire:

Enregistrer un commentaire