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.

Dan H
  • 3,524
  • 3
  • 35
  • 46

2 Answers2

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.

Florent B.
  • 41,537
  • 7
  • 86
  • 101
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')
Ferro Fang
  • 113
  • 1
  • 7