【发布时间】:2015-12-23 15:06:35
【问题描述】:
我在 python 中从 Selenium Ide 导入了代码。硒测试工作正常,无需点击项目,滚动无缝点击项目。 HTML硒代码:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head profile="http://selenium-ide.openqa.org/profiles/test-case">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<link rel="selenium.base" href="http://www.amazon.com/" />
<title>New Test</title>
</head>
<body>
<table cellpadding="1" cellspacing="1" border="1">
<thead>
<tr><td rowspan="1" colspan="3">New Test</td></tr>
</thead><tbody>
<tr>
<td>open</td>
<td>/</td>
<td></td>
</tr>
<tr>
<td>clickAndWait</td>
<td>css=[alt="Deals in Books"]</td>
<td></td>
</tr>
</tbody></table>
</body>
</html>
但在 Python 中,除非您滚动单击到所需的项目,否则它不起作用。
from selenium import webdriver
import unittest, time, re
class Untitled(unittest.TestCase):
def setUp(self):
self.driver = webdriver.Firefox()
self.driver.implicitly_wait(30)
self.base_url = "http://www.amazon.com/"
self.verificationErrors = []
self.accept_next_alert = True
def test_untitled(self):
driver = self.driver
driver.get(self.base_url)
driver.find_element_by_css_selector("a.feed-carousel-control.feed-right > span.gw-icon.feed-arrow").click()
driver.find_element_by_css_selector("a.feed-carousel-control.feed-right > span.gw-icon.feed-arrow").click()
driver.find_element_by_css_selector("a.feed-carousel-control.feed-right > span.gw-icon.feed-arrow").click()
driver.find_element_by_css_selector("a.feed-carousel-control.feed-right > span.gw-icon.feed-arrow").click()
driver.find_element_by_css_selector("[alt=\"Deals in Books\"]").click()
def tearDown(self):
self.driver.quit()
self.assertEqual([], self.verificationErrors)
我在不同的 selenium 定位器和 xpath css 中进行了测试,它可以工作,但在 python 中没有滚动点击元素不起作用。
【问题讨论】:
-
“不工作”是什么意思?没有什么?错误信息?你试过什么?究竟是什么问题?
标签: python html css selenium xpath