Answer the question
In order to leave comments, you need to log in
How to click on a button using Selenium?
Good afternoon
I can not figure out how to click on the button, as it occurs in several parts of the page.
I tried that, but it doesn't work...
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
import pandas as pd
import time
driver = webdriver.Chrome(executable_path='D:\chromedriver.exe')
driver.get("https://www.soglasie.ru/agent_search/")
search = driver.find_element_by_xpath("//input[@class='input-smart__input']")
search.send_keys('Иван')
button = driver.find_element_by_xpath("//div[@class='s-btn']")
button.click()
#button_c = driver.find_element_by_tag_name("div.s-btn__content")[7].click()
#Такой вариант не работает
try:
main = WebDriverWait(driver, 30).until(
EC.presence_of_element_located((By.TAG_NAME, "div.check"))
)
print(main.text)
except:
driver.quit()
driver.quit()
Answer the question
In order to leave comments, you need to log in
At least specify which button to press
. Through XPath, you can find it as follows:
driver.find_element_by_xpath("//span[text()='Показать еще']")
from selenium.common.exceptions import NoSuchElementException
search = driver.find_element_by_xpath("//input[@class='input-smart__input']")
search.send_keys('Иван')
button = driver.find_element_by_xpath("//div[@class='s-btn']")
button.click()
while True:
while True:
# Если данные все еще загружаются, классы кнопки меняются на `s-btn__loader`
if driver.find_elements_by_class_name('s-btn__loader'):
time.sleep(5)
else:
break
try:
load_more_btn = driver.find_element_by_xpath("//span[text()='Показать еще']")
except NoSuchElementException:
print('Загрузили страницу до конца')
break
load_more_btn.click()
time.sleep(5)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question