dưới đây là mã kiểm tra, khi chuột được hovererd trên hình ảnh, và về cơ bản tôi muốn hình ảnh được bấm ....python selen nhấp yếu tố thứ n
<ul id="product-list">
<li class="product one-col new">
<ul>
<li class="image" title="sample image">
<a href="#product/1d77e790-f74a-3859-97db-c513cbece39c">
<img width="" height="" alt="" src="/content/images/1.jpg"></img>
<span class="new"> … </span>
<span class="hover"></span>
</a>
<p class="retailer"> … </p>
<p class="brand"></p>
</li>
<li class="price"> … </li>
<li class="name" title="sample image"> … </li>
<li class="first-seen"> … </li>
</ul>
</li>
<li class="product one-col new"> … </li>
<li class="product one-col new"> … </li>
<li class="product one-col new"> … </li>
tôi đang sử dụng selen python, và đã thử bên dưới để nhấp vào liên kết span (hover)
browser.find_element_by_css_selector("ul#product-list > :first-child > ul > li.image > a > span.hover ").click
tuy nhiên điều này không có tác dụng ... bất kỳ ý tưởng nào?
cập nhật:
browser.find_element_by_css_selector("ul#product-list > :first-child > ul > li.image > a > span.hover ").click()
File "/usr/lib/python2.7/site-packages/selenium-2.35.0-py2.7.egg/selenium/webdriver/remote/errorhandler.py", line 164, in check_response
raise exception_class(message, screen, stacktrace)
ElementNotVisibleException: Message: u'Element is not currently visible and so may not be interacted with' ; Stacktrace:
at fxdriver.preconditions.visible (file:///tmp/tmp6Pgi9F/extensions/[email protected]/components/command_processor.js:8231)
at DelayedCommand.prototype.checkPreconditions_ (file:///tmp/tmp6Pgi9F/extensions/[email protected]/components/command_processor.js:10823)
at DelayedCommand.prototype.executeInternal_/h (file:///tmp/tmp6Pgi9F/extensions/[email protected]/components/command_processor.js:10840)
at DelayedCommand.prototype.executeInternal_ (file:///tmp/tmp6Pgi9F/extensions/[email protected]/components/command_processor.js:10845)
at DelayedCommand.prototype.execute/< (file:///tmp/tmp6Pgi9F/extensions/[email protected]/components/command_processor.js:10787)
update:
này không làm việc quá ...
browser.find_element_by_css_selector("ul#product-list > :first-child > ul > li.image > a ").click()
cập nhật:
.210actionchains cũng đã cố gắng, chuột click..still không may mắn ..
element = browser.find_element_by_css_selector("ul#product-list > :first-child > ul > li.image")
hov = ActionChains(browser).move_to_element(element)
hov.click()
SOLVED: cuối cùng này làm việc ...
element_to_hover_over = driver.find_element_by_css_selector("ul#product-list > :first-child ")
hover = ActionChains(driver).move_to_element(element_to_hover_over)
hover.perform()
if "" == driver.find_element_by_css_selector("span.hover").text:
driver.find_element_by_css_selector("span.hover").click()
trong dung dịch ur, là di chuột (variable name) là một tương tự mà được gọi sau này "span.hover"? – fartagaintuxedo
không .. di chuột đầu tiên là biến .. thứ hai là tên lớp cho thẻ span – krisdigitx