from selenium import webdriver
from selenium.webdriver.common.keys import Keys
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.common.action_chains import ActionChains
import time
def main():
driver = webdriver.Chrome()
driver.maximize_window()
driver.get("https://site.ru/")
btn_elem1 = driver.find_element_by_xpath("/html/body/div[2]/div[3]/div[2]/div[1]/div/ul/li[2]")
btn_elem1.click()
btn_elem2 = driver.find_element_by_xpath("/html/body/div[2]/div[3]/div[2]/div[1]/div/div[2]/div/p[1]/label/input")
btn_elem2.click()
btn_elem2.send_keys("login")
btn_elem3 = driver.find_element_by_xpath("/html/body/div[2]/div[3]/div[2]/div[1]/div/div[2]/div/p[2]/label/input")
btn_elem3.click()
btn_elem3.send_keys("pass")
btn_elem4 = driver.find_element_by_xpath("/html/body/div[2]/div[3]/div[2]/div[1]/div/div[2]/div/a")
btn_elem4.click()
time.sleep(1)
driver.get("https://site/1")
btn_elem5 = driver.find_element_by_xpath("/html/body/div[1]/div[3]/div[1]/fieldset/div[2]/img[1]")
btn_elem5.click()
action = ActionChains(driver)
action.key_down(Keys.CONTROL).send_keys("f").key_up(Keys.CONTROL).perform()
time.sleep(5)
if __name__ == "__main__":
main()
Everything works up to a point.
The browser opens, expands. I pass to the necessary site. I go to the Login tab, enter the login and password. I’m going to another page that I don’t have access to if I’m not logged in. I open there a spoiler with hidden text.
After which I want to call "Find" via Ctrl + F, but for some reason, it doesn’t work, nothing happens. And in general, as I understand it, the keys themselves do not work. As if they were not added, although it seems to be written at the beginning of the code.
And if the necessary text is found, then take a screenshot and go to https: // site / 2, if not, then immediately go to site / 2 and search there. In total there are about ten thousand pages, probably the address of the village should be somehow made through a variable? And something like through ++ how to do it in PHP, like plus one, so that it is added every time?
Or maybe somehow it can be done differently? Search for plain text throughout the page. And if there is, then a screenshot and transition further, if not, then immediately move on. (The asterisk calls a screenshot)
sila = driver.find_element_by_xpath("/html")
if 'Селява' in sila.text:
action.send_keys("*")
action.key_down(Keys.CONTROL).send_keys("s").key_up(Keys.CONTROL).perform()
driver.get("https://site/+1id") (вот как это сделать?)
else:
driver.get("https://site/+1id") (вот как это сделать?)
Two problems remain in general. This is how to find the text and how to make it go to the next id page. I would be very grateful for any help.