Подскажите пожалуйста, как передать данные в форму:
https://fedresurs.ru/messages/IsSearching необходимо выбрать ЮЛ При нажатии открывается новая форма. Тип сообщения я выбираю так:
select = Select(driver.find_element_by_id('ctl00_MainContent_ddlMessageTypeList'))
select.select_by_visible_text('Сообщение о выпуске независимой гарантии')
s = driver.find_element_by_xpath('//*[@id="ctl00_MainContent_btnSearch"]') #Кнопка поиск
s.click()
ЮЛ хотел выбрать так:
s = driver.find_element_by_id('ctl00_MainContent_txtCode').send_keys('555')
Но получаю ошибку, что элемент ctl00_MainContent_txtCode не найден.
Подскажите как правильно?
Попробовал так:
s = driver.find_element_by_xpath('//*@id="ctl00_MainContent_sfCompanySelector_txtObjectName"]') #находим строку поиска ЮЛ, клик
s.click()
Находим input для ввода ИНН
i = driver.find_element_by_css_selector('#aspnetForm > div.extsearch > table > tbody > tr:nth-child(2) > td > table > tbody > tr:nth-child(3) > td:nth-child(2)')
i.send_keys('4444444444')
Ошибка
selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: {"method":"css selector","selector":"#aspnetForm > div.extsearch > table > tbody > tr:nth-child(2) > td > table > tbody > tr:nth-child(3) > td:nth-child(2)"}
(Session info: chrome=55.0.2883.87)
получилось так, только теперь я не захожу на 10, 20, 30 стр ... создается файлик с кодом страницы, 7,8,9, 11.. часть кода использующая selenium не моя, кто может объяснить почему я пропускаю эти страницы?
from selenium import webdriver
from selenium.common.exceptions import TimeoutException
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By
import time
from bs4 import BeautifulSoup
def get_list(n): # n page number
timeout = 3
try:
# waiting for the paginator to have current page as class "active" li with span
element_present = EC.presence_of_element_located((By.XPATH, '//li[@class="active"]/a/span[text()="{}"]'.format(n)))
WebDriverWait(driver, timeout).until(element_present)
except TimeoutException:
print("Timed out waiting for page to load")
# looking for record names and record authors
lst_divs = driver.find_elements_by_class_name('display-field.message-in-list')
lst_as = driver.find_elements_by_xpath('//div[starts-with(@id, "ctl00_MainContent_lvMessageList_ctrl")]')
for d, a in zip(lst_divs, lst_as):
print('\t{} :: {}'.format(d.text, a.text))
driver = webdriver.Chrome(executable_path=r"C:\Program Files (x86)\Google\Chrome\Application\chromedriver.exe")
url = 'http://fedresurs.ru/messages/IsSearching'
driver.get(url)
while True:
# getting last page
a = driver.find_element_by_css_selector('div.right > table.paging td > ul > li:last-child')
last_page = int(a.text)
# print(last_page)
# go over first page
# print('Page {}'.format(last_page-9))
get_list(last_page-9)
# loop thru other pages
for i in range(last_page-9, last_page):
# print('Page {}'.format(i + 1))
if i < 11:
link = "javascript:__doPostBack('ctl00$MainContent$ucTopDataPager$ctl00$ctl{0:02d}','')".format(i)
# print('1 vetka ' + str(i))
else:
link = "javascript:__doPostBack('ctl00$MainContent$ucTopDataPager$ctl00$ctl{0:02d}','')".format(int(str(i)[-1])+1)
# print('2 vetka ' + str(int(str(i)[-1]) + 1) + 'page ' + str(i))
# finding next page
a = driver.find_element_by_xpath('//a[@href="{}"]'.format(link))
# click, wait + parse
a.click()
# getting page
html = driver.page_source
soup = BeautifulSoup(html)
out = open('Page_{}'.format(i) + '.txt', 'w')
out.writelines(soup.prettify())
# print('Printing page {}'.format(i))
time.sleep(5)
get_list(i + 1)
np = driver.find_element_by_css_selector('table.paging td:last-child a')
if np.text == '...':
np.click()
# element_present = EC.presence_of_element_located((By.XPATH, '//li[@class="active"]/a/span[text()="{}"]'.format(last_page + 1)))
# WebDriverWait(driver, 3).until(element_present)
time.sleep(5)
else:
break
driver.close()