0

I am trying to scrape the contents using selenium and since the xpaths are similar, i am using a list so that i don't need to write 'find_element_by_xpath'. I wrote a function to get the contents but the contents are not getting extracted. Here is my code:

def find_text(path):
    driver.find_element_by_xpath(path).text

ph_packages= ["PAY_AS_YOU_TALK", "EVENINGS_AND_WEEKEND_EXTRA"]
for i in ph_packages:
    ph_name.append(find_text('//*[@id="productButtonControls_ST_%s"]/label' % i))
    print ph_name

There is no output with this code but when i used the same code without the function, then it is working totally fine.

ph_packages= ["PAY_AS_YOU_TALK", "EVENINGS_AND_WEEKEND_EXTRA"]
for i in ph_packages:
    ph_name.append(driver.find_element_by_xpath('//*[@id="productButtonControls_ST_%s"]/label' % i).text)

I think i am doing some mistake with writing the function. Could someone help me with this?

1 Answer 1

2

That is because your function doesn't return anything

def find_text(path):
    driver.find_element_by_xpath(path).text

Should be

def find_text(path):
    return driver.find_element_by_xpath(path).text
Sign up to request clarification or add additional context in comments.

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.