Reputation: 31
I am having trouble using explicit wait with Selenium. I keep getting the following error.
File "C:/Users/username/path/craigslist_scrape.py", line 108, in <module>
WebDriverWait(driver,5).until(EC.text_to_be_present_in_element_value(By.XPATH('//p[@class="reply-email-address"]/a[@class="mail app"]')))
TypeError: 'str' object is not callable
My code is as follows. Basically, I am trying to scrape the email address. However, most of the time, the email address is not visible unless I click 'reply'. What I am trying to do is to get Selenium to click Reply and wait until the email address is visible and then scrape. I have tried using a couple of different methods, but kept getting the same error. Not sure what exactly happened. Hope somebody can help.
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.support.select import Select
from selenium.common.exceptions import NoSuchElementException
from selenium.common.exceptions import TimeoutException
driver=webdriver.Chrome()
driver.get('https://nh.craigslist.org/search/reb')
link_list=[]
link=driver.find_elements_by_xpath('//li[@class="result-row"]/a[@href]')
for elem in link:
print(elem.get_attribute('href'))
link_list.append(elem.get_attribute('href'))
for link in link_list:
driver.get(link)
driver.find_element_by_xpath('//div[@class="actions-combo"]/button[@role="button"]').click()
WebDriverWait(driver,5).until(EC.text_to_be_present_in_element_value(By.XPATH('//p[@class="reply-email-address"]/a[@class="mail app"]')))
email=driver.find_element_by_xpath('//p[@class="reply-email-address"]/a').text
print(email)
Upvotes: 1
Views: 996
Reputation: 1273
Okay I have realised what you want to do ...
The problem is that you are calling the wrong function with wrong parameters. Here is the correct way to call it :)
WebDriverWait(driver, 20).until(EC.visibility_of_element_located((By.XPATH, '/html/body/section/section/header/div[2]/div/div[1]/aside')))
The main problem is that you are telling the function that which element it should be looking for using which function ...
Here is SO answer that answers it better than I do: Selenium - wait until element is present, visible and interactable
Upvotes: 2