Python:Selenium模拟onclick [英] Python: Selenium to simulate onclick

查看:3288
本文介绍了Python:Selenium模拟onclick的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用python来玩一个简单的javagame,这个javagame是我为一个类作业而创建的。我试图让Python打开一个网页,并使用表单按钮来输入数字。我认为这接近我所需要的,但我不知道如何修复第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()

按钮一是第一个按钮。

解决方案

您的CSS选择器无效。试试这个:

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



> / p>

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.

解决方案

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.

这篇关于Python:Selenium模拟onclick的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆