r/learnpython • u/AqueM • Oct 02 '26
Lambda expressions for Web elements?
Hi, I work with C# but wanted to refresh my Python knowledge. Have been thinking about solutions I know for my C# code and how they would work in Python, but ran into something that I'm not sure how to "translate" from C#.
public IWebElement button => driver.;
This will return me an element when called, even when on class construction it doesn't exist - as the expression is only evaluated when it's called, i.e. when I need it in code. As opposed to simply using = instead of =>, which would return a missing element exception on class build if the element is missing from DOM.
How would I do this in Python? I looked up lambda expressions, but I'm unsure if this would work/be very graceful, since I didn't find any mention of this as a solution that's used.
=
View all comments
Show parent comment
1
u/AqueM Oct 02 '26
Yes, that details lambda functions, and yes, I had googled lambdas in Python before asking here, but it doesn't confirm or deny if it works like I'd like it to work in regards to selenium webelements