0

I am trying to write script which needs to open two boxes on webpage and get proper email address. I believe i am not inheriting elements on webpage properly. Please view my code below:

   try:
            WebDriverWait(driver, 10).until(EC.visibility_of_element_located((By.CSS_SELECTOR, "body > section > section > section > div.mapAndAttrs > p:nth-child(2)")))
            xxx = driver.find_element_by_css_selector("#titletextonly").text
            #Click on Reply button
            WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "button.reply-button.js-only"))).click()
            WebDriverWait(driver, 20).until(EC.visibility_of_element_located((By.CSS_SELECTOR, 'body > section > section > header > div.reply-button-row > div > div.reply-info.js-only')))
            #target email address
            to = driver.find_element_by_css_selector("body > section > section > header > div.reply-button-row > div > div.reply-info.js-only > aside.reply-flap.js-captcha > ul > li.reply-email > p > a").text
        except:

Here is sample page from which I need to extract email: https://newyork.craigslist.org/fct/cto/d/ridgefield-2003-bmw-x5-30-xdrive/7212695001.html

Email is located in "reply" button and then another "show email" button.

Any guidance is greatly appreciated.

1 Answer 1

1

you can use:

WebDriverWait(driver, 10).until(EC.visibility_of_element_located((By.CSS_SELECTOR, "body > section > section > section > div.mapAndAttrs > p:nth-child(2)")))
xxx = driver.find_element_by_css_selector("#titletextonly").text
#Click on Reply button
WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "button.reply-button.js-only"))).click()
WebDriverWait(driver, 20).until(EC.visibility_of_element_located((By.CSS_SELECTOR, 'body > section > section > header > div.reply-button-row > div > div.reply-info.js-only')))
#target email address
WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, 'body > section > section > header > div.reply-button-row > div > div.reply-info.js-only > aside > ul > button'))).click()
WebDriverWait(driver, 20).until(EC.presence_of_element_located((By.CSS_SELECTOR, 'body > section > section > header > div.reply-button-row > div > div.reply-info.js-only > aside')))
texto = WebDriverWait(driver, 20).until(EC.presence_of_element_located((By.CSS_SELECTOR, 'body > section > section > header > div.reply-button-row > div > div.reply-info.js-only > aside > ul > li.reply-email > p > a'))).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.