I am looking to implement method chaining of Selenium WebDriverWaits.
To start with, this block of code implementing a single WebDriverWait works perfect:
from selenium import webdriver
from selenium.webdriver.support.ui import WebDriverWait
options = webdriver.ChromeOptions()
options.add_argument("start-maximized")
options.add_argument('disable-infobars')
driver = webdriver.Chrome(chrome_options=options, executable_path=r'C:\Utility\BrowserDrivers\chromedriver.exe')
driver.get('https://www.facebook.com')
element = WebDriverWait(driver, 5).until(lambda x: x.find_element_by_xpath("//input[@id='email']"))
element.send_keys("method_chaining")
As per as my current requirement I have to implement chaining of two WebDriverWait instances as the idea is to fetch the element returned from the first WebDriverWait as an input to the (chained) second WebDriverWait.
To achieve this, I followed the discussion method chaining in python tried to use the use Python's lambda
function through method chaining using Pipe - Python library to use infix notation in Python.
Here is my code trial:
from pipe import *
from selenium import webdriver
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
options = webdriver.ChromeOptions()
options.add_argument("start-maximized")
options.add_argument('disable-infobars')
driver = webdriver.Chrome(chrome_options=options, executable_path=r'C:\WebDrivers\chromedriver.exe')
driver.get('https://www.facebook.com')
element = WebDriverWait(driver,15).until((lambda driver: driver.find_element_by_xpath("//input[@id='email']"))
| where(lambda driver: driver.find_element_by_css_selector("table[role='presentation']")))
element.send_keys("method_chaining")
I am seeing an error as:
DevTools listening on ws://127.0.0.1:52456/devtools/browser/e09c1d5e-35e3-4c00-80eb-cb642fa273ad
Traceback (most recent call last):
File "C:\Users\Soma Bhattacharjee\Desktop\Debanjan\PyPrograms\python_pipe_example.py", line 24, in <module>
| where(lambda driver: driver.find_elements(By.CSS_SELECTOR,"table[role='presentation']")))
File "C:\Python\lib\site-packages\pipe.py", line 58, in __ror__
return self.function(other)
File "C:\Python\lib\site-packages\pipe.py", line 61, in <lambda>
return Pipe(lambda x: self.function(x, *args, **kwargs))
File "C:\Python\lib\site-packages\pipe.py", line 271, in where
return (x for x in iterable if (predicate(x)))
TypeError: 'function' object is not iterable
Followed the following discussions:
- python3 TypeError: 'function' object is not iterable
- TypeError: 'function' object is not iterable' Python 3
Still no clue what I am missing.
Can someone guide me where I am going wrong?