0

So, I'm not very familiar with Python nor HTML But I made this code so I could vote in a poll on a website, as far as I'm concerned there is nothing morally wrong with this idea because it is encouraged to refresh your page so you can vote for the same person over and over again. I want to use the code to click a button. Below is the code I've got so far

from selenium import webdriver
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.keys import Keys
import time

PATH = "C:\Program Files (x86)\chromedriver.exe"
driver = webdriver.Chrome(PATH)

driver.get("https://www.nfl.com/voting/rookies/")

So I've gotten as far as going onto the website but I'm not sure if the person I am going to vote for has an HTML ID/Class/Element, I'm not really sure how to find it with inspect element or if it even has an HTML ID/Class/Element. If I want to vote for someone like Justin Herbert of the LAC, how should my code look? How would I click the white button next to Justin with Python? Thank you!

2
  • Suggest you get familiar with selenium and how to find html elements selenium-python.readthedocs.io/locating-elements.html. First you need to find the proper element matching the one you want to vote for using driver.find_element_by*locatorType*('Value'). This will return you an WebElement. Then you use method from the WebElement class (i.e click) for example to perform an action. Same idea for the Botton Commented Dec 23, 2020 at 0:59
  • If you provide an HTML code, it would be easier to help you Commented Dec 23, 2020 at 1:08

1 Answer 1

1

From the driver.get we get a popup, an iframe to handle and we need to click on the div tag that responds to a player. You should be able to translate these steps to your player.

Popup:

<div class="slidedown-footer" id="slidedown-footer"><button class="align-right primary slidedown-button" id="onesignal-slidedown-allow-button">Allow</button><button class="align-right secondary slidedown-button" id="onesignal-slidedown-cancel-button">No Thanks</button><div class="clearfix"></div></div>

Iframe:

<iframe title="Content from Riddle" style="border: none; width: 100%; position: static; opacity: 1; height: 539px !important;" src="https://www.riddle.com/a/288390"></iframe>

Player:

<span class="list-title ng-binding" ng-bind-html="item.title">Salvon Ahmed, MIA</span>

For this we use the following:

driver.get("https://www.nfl.com/voting/rookies/")
wait=WebDriverWait(driver, 10)
wait.until(EC.element_to_be_clickable((By.CSS_SELECTOR, "#onesignal-slidedown-cancel-button"))).click()    
wait.until(EC.frame_to_be_available_and_switch_to_it((By.XPATH, "//iframe[@title='Content from Riddle']")))  
wait.until(EC.element_to_be_clickable((By.XPATH, "//span[text()='Salvon Ahmed, MIA']/parent::div/parent::div/div[2]/div"))).click()

Import

from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait 
from selenium.webdriver.support import expected_conditions as EC
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.