python硒查找元素并单击-不可单击

时间:2020-03-15 17:34:00

标签: python selenium web-scraping

我试图单击“下载CSV”按钮,但找不到要单击的正确元素。将chrome驱动程序与Selenium结合使用,并尝试从DropdownWrapper直到并包括Download-Icon的屏幕快照中显示的几个级别的元素,然后遇到相同的错误:

selenium.common.exceptions.WebDriverException:消息:未知错误:元素...在点(318,27)处不可单击。

这是我尝试过的一些语句,所有语句都会导致相同的错误:

driver.find_element_by_xpath('/html/body/div[1]/div/div[1]/div/div[2]/div[2]/div/div[1]/div[3]/div[2]/button/svg/g/g/g/g').click()
driver.find_element_by_class_name('DropdownMenuWrapper-sc-1akf9v9-2').click()
driver.find_element_by_class_name('DownloadCsvButton-sc-1iuvgd5-2').click()

这是html:

<div class="DropdownWrapper-sc-1akf9v9-1 kIEUeW" direction="right" content="[object Object]"><div class="DropdownMenuWrapper-sc-1akf9v9-2 iGSrFC"><div class="DropdownMenuContainer-sc-1akf9v9-0 dYvTtz" direction="right" content="[object Object]"><svg class="CloseIconWrapper-sc-1tws3k5-6 gmjDxQ Svg-sc-190khmc-0 emBxVZ" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 14 14" id="closeCsvTrialDropDown" size="15" color="slate"><g stroke="none" stroke-width="1" fill="none" fill-rule="evenodd"><g class="close-icon" transform="translate(-962.000000, -419.000000)" stroke-width="0.5" fill-rule="nonzero"><g transform="translate(211.000000, 405.000000)"><g id="Close-Icon" transform="translate(752.000000, 15.000000)"><path d="M11.147541,0.147540984 L6.3442623,4.95081967 C6.14754098,5.14754098 5.83606557,5.14754098 5.6557377,4.95081967 L0.852459016,0.147540984 C0.655737705,-0.0491803279 0.344262295,-0.0491803279 0.163934426,0.147540984 L0.163934426,0.147540984 C-0.0327868852,0.344262295 -0.0327868852,0.655737705 0.163934426,0.836065574 L4.96721311,5.63934426 C5.16393443,5.83606557 5.16393443,6.14754098 4.96721311,6.32786885 L0.147540984,11.147541 C-0.0491803279,11.3442623 -0.0491803279,11.6557377 0.147540984,11.8360656 L0.147540984,11.8360656 C0.344262295,12.0327869 0.655737705,12.0327869 0.836065574,11.8360656 L5.63934426,7.03278689 C5.83606557,6.83606557 6.14754098,6.83606557 6.32786885,7.03278689 L11.147541,11.852459 C11.3442623,12.0491803 11.6557377,12.0491803 11.8360656,11.852459 L11.8360656,11.852459 C12.0327869,11.6557377 12.0327869,11.3442623 11.8360656,11.1639344 L7.04918033,6.3442623 C6.85245902,6.14754098 6.85245902,5.83606557 7.04918033,5.6557377 L11.852459,0.852459016 C12.0491803,0.655737705 12.0491803,0.344262295 11.852459,0.163934426 L11.852459,0.163934426 C11.6557377,-0.0327868852 11.3442623,-0.0327868852 11.147541,0.147540984 Z" id="Close-Button"></path></g></g></g></g></svg><div class="TitleLabelWrapperOrange-sc-1tws3k5-2 fjIicO">Feature unavailable on free trial</div><div class="SubTitleLabelWrapper-sc-1tws3k5-1 eFPKTl">Upgrade today to download CSV Files</div><div class="ListOfItemsWrapper-sc-1tws3k5-4 jOguBA"><ul class="ListOfItems-sc-1tws3k5-3 fkvYOb"><li>Find a profitable product to sell today</li><li>Access Jungle Scout’s full suite of Amazon selling tools</li><li>Rely on the most accurate sales data in the industry</li><li>Unlock best-in-class training tutorials and courses</li><li>Join 225,000+ of the world’s top FBA sellers</li></ul></div><div class="PopupButtonWrapper-sc-1tws3k5-0 kmrTpx"><button class="CsvTrialButton-sc-1tws3k5-5 gcGSc ButtonWrapper-sc-1vti96x-0 dxrAIm"><div class="ButtonContent-sc-1vti96x-1 mNloU">Upgrade Now</div></button><button class="CsvTrialButton-sc-1tws3k5-5 gcGSc ButtonWrapper-sc-1vti96x-0 eInnCg"><div class="ButtonContent-sc-1vti96x-1 bosOtE">Learn More</div></button></div></div></div><button class="DownloadCsvButton-sc-1iuvgd5-2 hhVvqT">Download CSV<svg class="StyledDownloadIcon-sc-1iuvgd5-3 jDCjZI IconWrapper-b39pdp-0 huocMM" color="#222222" viewBox="0 0 15 15"><g id="Page-1" stroke="none" stroke-width="1" fill="none" fill-rule="evenodd"><g id="Download---Icon" fill="#222222"><g id="Download-CSV-Button"><g id="Download-Icon" fill-rule="nonzero"><path d="M14.0625,8.27027027 C13.575,8.27027027 13.2375,8.61486486 13.2375,9.16216216 L13.2375,13.0540541 L1.7625,13.0540541 L1.7625,9.16216216 C1.7625,8.63513514 1.44375,8.27027027 0.9375,8.27027027 C0.43125,8.27027027 0.1125,8.61486486 0.1125,9.16216216 L0.1125,13.9459459 C0.1125,14.472973 0.43125,14.8378378 0.9375,14.8378378 L14.0625,14.8378378 C14.55,14.8378378 14.8875,14.4932432 14.8875,13.9459459 L14.8875,9.16216216 C14.8875,8.63513514 14.55,8.27027027 14.0625,8.27027027 Z" id="Shape"></path><path d="M7.5,0.162162162 C7.0125,0.162162162 6.675,0.506756757 6.675,1.05405405 L6.675,7.54054054 L5.775,6.56756757 C5.45625,6.22297297 4.95,6.22297297 4.63125,6.56756757 C4.3125,6.91216216 4.3125,7.45945946 4.63125,7.80405405 L6.91875,10.277027 C7.0875,10.4594595 7.33125,10.5405405 7.5,10.5405405 C7.74375,10.5405405 7.9125,10.4594595 8.08125,10.277027 L10.36875,7.80405405 C10.6875,7.45945946 10.6875,6.91216216 10.36875,6.56756757 C10.05,6.22297297 9.54375,6.22297297 9.225,6.56756757 L8.325,7.62162162 L8.325,1.05405405 C8.325,0.608108108 7.9125,0.162162162 7.5,0.162162162 Z" id="Shape"></path></g></g></g></g></svg></button></div>

,并且只能提供页面的屏幕截图,因为需要登录: enter image description here enter image description here

1 个答案:

答案 0 :(得分:0)

您可以尝试使用JavaScript单击来单击元素。
您可以这样做:

download_button = driver.find_element_by_xpath("//div[@class='DropdownWrapper-sc-1akf9v9-1 kIEUeW']//button[contains(text(),'Download CSV')]")
driver.execute_script("arguments[0].click();", download_button)