I have a program that presses buttons on the site, but some buttons are out of sight (that is, to see them and press you to have to scroll through the page), how best can I solve this problem, given that I don’t know which of the buttons will be out of sight.
3 Answers
You can copy the Xpath or CSS selector with inspect elements on the website.
By XPATH:
driver.find_element(By.XPATH("Paste here")).click()
By CSS selector:
driver.find_element(By.CSS_SELECTOR("Paste here")).click()
Here are the attributes available for the By class:
- ID = "id"
- XPATH = "XPath"
- LINK_TEXT = "link text"
- PARTIAL_LINK_TEXT = "partial link text"
- NAME = "name"
- TAG_NAME = "tag name"
- CLASS_NAME = "class name"
- CSS_SELECTOR = "css selector"
1 Comment
Maxwell
I know how to find the element. I made a little mistake, I click not through selenium, but through pyautogui, and the problem is actually described above
pyautogui only accepts the coordinates, as stated in the documentation In example:
`pyautogui.click(x=100, y=200) # move to 100, 200, then click the left mouse button.`
if you would like to select hidden elements a library like Selenium would be better. An example would be:
driver.findElement(By.className("AddContentBTN")).click();
This way you can select any element and search the dom.
Comments
The latest version definitely supports clicking on screenshots:
>>> import pyautogui
>>> button7location = pyautogui.locateOnScreen('calc7key.png', confidence=0.9)
>>> button7location
Box(left=1416, top=562, width=50, height=41)
Documentation here