1

I am trying to use python to play a simple javagame that I made for a class assignment. I am trying to make python open up a webpage and use the form buttons to input numbers. I think this is close to what I need but I am not sure how to fix line 7

(li = browser.find_element_by_css_selector('#button-one li:predict.input.value += 1'))

from selenium import webdriver

url = 'http://alexcassell.com/javagame'

browser = webdriver.Firefox()
browser.get(url)
li = browser.find_element_by_css_selector('#button-one li:predict.input.value += 1')
li.click()

Button-one is the ID of the first button.

2 Answers 2

1

You CSS selector is not valid. Try this one instead:

li = browser.find_element_by_css_selector('#button-five')

Note that you can get a CSS selector in your browser by inspecting the element and clicking on "Copy unique selector" in the context menu.

Sign up to request clarification or add additional context in comments.

Comments

0

try:

li = browser.find_element_by_css_selector('input#button-one[onclick="predict.input.value += 1"]')

or without element name "input":

li = browser.find_element_by_css_selector('#button-one[onclick="predict.input.value += 1"]')

or if there is only element whose "id" is "button-one", simply write:

li = browser.find_element_by_css_selector('#button-one')

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.