用硒单击img

用硒单击img

对于使用Python和一般的代码进行编码我还是很陌生。 到目前为止,我已经尝试过:

driver.find_element_by_xpath("//img[contains(@src,'/images/excel.png')])

driver.find_element_by_css_selector("/images.excel.png")

driver.execute_script("javascript: exportExcel('')")

driver.find_element_by_xpath("//td[@class='pageControl'][img/@src='/images/excel.png']").click()

我们将不胜感激,谢谢您。

更新: I've attached an additional image of the html code that is above the code depicted in the DOM in the previous image. There does not seem to be an iFrame obstructing the img

更新2:作为替代解决方案,我使用pyautogui将鼠标物理移动到指定坐标以单击页面上的图标。到目前为止,xpath未能识别该元素。

zhxru 回答:用硒单击img

我将通过单击父td元素来解决此问题。我对您的问题的理解是,您正在尝试触发excelExport()函数。

使用CSS选择器:

td_element = driver.find_element_by_css_selector('td[onclick="javascript: excelExport()"]')
td_element.click()

可以使用以下方式选择图像本身:

image = driver.find_element_by_css_selector('img[src="/images/excel.png"]')

未经测试(但可能会起作用)

driver.execute_script("excelExport();")

运行driver.execute_script时,无需指定语言,因为它将是javascript。

,

我还没有看到您尝试在解决方案中尝试单击Javascript,所以让我们尝试一下。通常,这是我点击怪异或时髦元素的全部内容。

image = driver.find_element_by_xpath("//img[contains(@src,'/images/excel.png')]")

driver.execute_script("arguments[0].click();",image)

希望这会有所帮助。

,

使用Action类单击:

element = driver.find_element_by_xpath("//table//tbody//tr//td[contains(@class,'pageControl') and contains(.,'Excel')]//img[contains(@src,'/images/excel.png')]")
action = ActionChains(driver)
action.move_to_element(element).click(element).perform()

正在导入:

from selenium.webdriver import ActionChains
本文链接:https://www.f2er.com/3157578.html

大家都在问