0

I'm trying to create a small script to tell me if addresses need a certain type of shipping.

I have a list of addresses to input into a website and it will return what type they are. Why is this returning none, even though when I check the element in selenium it's there? And technically it has to be there, to even pass the "EC.presence_of_element_located" code.

browser = webdriver.Chrome()

browser.get('courier_website')

field = browser.find_element_by_id("txt-address-auto-complete")

field.send_keys("12 test Street")

WebDriverWait(browser, 10).until(EC.element_to_be_clickable((By.XPATH, "//li[@class='ui-menu-item']/a[contains(@id, 'ui-id-')]")))

browser.find_element_by_xpath("//li[@class='ui-menu-item']/a[contains(@id, 'ui-id-')]").click()

WebDriverWait(browser, 10).until(EC.presence_of_element_located((By.XPATH, '//*[@id="delivery-details-addresstype" and text() != ""]')))

post = browser.find_element_by_xpath('//*[@id="delivery-details-addresstype"]').get_attribute('value')

print(post)

Output is "None"

HTML I'm trying to get the text out of

<table class="delivery-details">
                        <tbody><tr>
                            <th colspan="3" id="delivery-details-addresstype">Residential Delivery Zone Address</th>
                        </tr>
6
  • 1
    What is None is not the element, it's the attribute named value of that element Commented Jan 10, 2020 at 8:15
  • So how do I get the text inside the element? Commented Jan 10, 2020 at 8:16
  • 1
    That depends on the type of element you have. Maybe try also posting the related HTML Commented Jan 10, 2020 at 8:17
  • ahh ok sorry, updated the OP Commented Jan 10, 2020 at 8:20
  • 2
    Have you already tried .get_attribute('innerHTML') ? Commented Jan 10, 2020 at 8:36

2 Answers 2

2

Instead of browser.find_element_by_xpath(//required_path).get_attribute('value'), use:

browser.find_element_by_xpath(//required_path).get_attribute('innerHTML')
Sign up to request clarification or add additional context in comments.

Comments

0

In some cases 'textContent' has worked for me

browser.find_element_by_xpath(//path).get_attribute('textContent')

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.