sumixam;
나는 프로그래밍 웹 사이트 콘텐츠에 액세스하려면 우분투 서버에서 스크립트를 실행하는 버튼을 클릭하는 것을 시도하고있다. 내가 가진 사이트에 도달하기 위해 노력하고 레서피를
이건 내 코드입니다 :
driver = webdriver.Firefox(executable_path="/home/ubuntu/.linuxbrew/Cellar/geckodriver/0.26.0/bin/geckodriver",options=options)
data = []
# In[34]:
# click GDPR full-width banner
start_time = datetime.now()
driver.get("http://allrecipes.co.uk/")
time.sleep(10)
# gdpr_button = driver.find_element_by_link_text("Continue")
#gdpr_button = driver.find_element_by_xpath('//button[text()="Continue"]')
driver.find_element_by_xpath("//input[@style='order:2' and @onclick='sendAndRedirect()']").click()
# //input[@onclick='sendAndRedirect()']
# <button style="order:2" onclick="sendAndRedirect();">Continue</button>
그러나, 나는 요소에 도달 얻을 수 없다
selenium.common.exceptions.TimeoutException: Message: connection refused
어떻게 GDPR 형태로 '계속'버튼을 액세스 할 수 있습니까? 당신의 도움을 주셔서 감사합니다
DebanjanB :
원하는 요소는 동적 요소가 너무 / 위치하는 것입니다 click()
당신이 유도하는 데 필요한 요소에 WebDriverWait을 을 위해 element_to_be_clickable()
당신은 다음 중 하나를 사용할 수 있습니다 로케이터 전략 :
사용
CSS_SELECTOR
:WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "button[onclick^='sendAndRedirect']"))).click()
사용
XPATH
및 innerText와의 이벤트 :WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//button[text()='Continue']"))).click()
사용
XPATH
및 온 클릭 이벤트 :WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//button[starts-with(@onclick, 'sendAndRedirect')]"))).click()
참고 : 다음과 같은 수입을 추가해야합니다 :
from selenium.webdriver.support.ui import WebDriverWait from selenium.webdriver.common.by import By from selenium.webdriver.support import expected_conditions as EC