I'm looking to click the button highlighted in the screenshot below; have tried with pyautogui but found results to be inconsistent so trying selenium instead.
I'm having trouble identifying the button to then call the click function.
Here's the HTML
Alternatively perhaps I could run the 'ng-click' function, unsure how to approach that. If I do this, I'll need to pipe through 'index', from what I can tell from this HTML (my understanding of HTML is minimal)
Thank you
You can have browser to figure out the button CSS selector for you.
Here's how to do that in Chrome:
- Open your page in Chrome
- Right-click on your button and select the Inspect Element from the context menu
- The Inspector window will open with the button's HTML markup selected.
- Right-click the selected HTML line(s) and select Copy -> CSS Selector.
- Paste the CSS selector into the code below
And here's the code to click your button:
from selenium import webdriverbrowser = webdriver.Chrome('/path/to/chromedriver')
browser.get('your/website/url')
button = browser.find_element_by_css_selector('paste the CSS selector here')
button.click()
Hope this helps.
PS: Here's an excellent article (a chapter from the Automate the boring stuff with Python book) on web scraping and browser automation using BeautifulSoap and Selenuim.