1

I'm converting a project over from c#/selenium to python/selenium.

We have a drop down within the site which has an id which is incremental, i.e:

Upl-employmentstatus-radio-01
Upl-employmentstatus-radio-02
......

So within the page model object we have added an element as follows:

public IWebElement EmploymentStatus(int option) => _driver.FindElement(By.Id($"upl-employmentstatus-radio-{option}")

the int option allows us to replace the value it selects depending on c#/selenium test.

So what is the equivalent is python for the page model element?

i've currently got the following:

self.Title = WebDriverWait(self.driver, 60).until(ec.visibility_of_element_located(webapp.driver.find_element_by_id("upl-title-radio-{option}")))

2 Answers 2

2

The Python equivalent of C#'s string interpolation is f-string

f"upl-title-radio-{option}"
Sign up to request clarification or add additional context in comments.

Comments

0

In python use this code for a page object. Then you can pass in the variable and return the path.

 def self.Title(option):
     return WebDriverWait(self.driver,60).until(ec.visibility_of_element_located(webapp.driver.find_element_by_id(f"upl-title-radio-{option}")))

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.