下拉菜单不会使用-Selenium和Python关闭

时间:2019-10-24 13:56:43

标签: python selenium selenium-webdriver

即使单击下拉菜单上的某个项目,它也不会关闭,而是保持打开状态。很奇怪。

from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
from selenium.webdriver.common.keys import Keys

chrome_options = Options()
chrome_options.add_argument("--disable-extensions")
chrome_options.add_argument("--disable-gpu")

# enable browser logging
d = DesiredCapabilities.CHROME
d['loggingPrefs'] = { 'browser':'ALL' }
driver = webdriver.Chrome(desired_capabilities = d, options=chrome_options)
driver.fullscreen_window()

driver.get("https://forsikringsguiden.dk/#!/bilforsikring/manuel")

maerke = driver.find_element_by_xpath('//*[@id="s2id_carSelectedMake"]/a').click()
driver.find_element_by_xpath('//*[@id="select2-results-1"]/li[75]').click()

我尝试添加:

driver.switch_to.active_element.send_keys(Keys.ENTER)
我在另一个SO线程中找到的

,但是没有用。

还尝试在最后一次click()之后添加send_keys(),但仍然无法正常工作。

更新:-仍然没有解决方案。

1 个答案:

答案 0 :(得分:0)

在大多数情况下,只需跳出下拉列表即可。试试这个解决方案,

ActiveWorkbook.Queries.Add Name:=strName, Formula:= _
        "let" & Chr(13) & "" & Chr(10) & "    Source = Excel.CurrentWorkbook(){[Name=" & strName & "]}[Content]," & Chr(13) & "" & Chr(10) & "    #""Changed Type"" = Table.TransformColumnTypes(Source,{{""Date"", type any}, {""Time"", type any}, {""Call"", type any}, {""Greet"", type any}, {""Listen"", type any}, {""Engage"", type any}, {""Act"", type any}, {""Deliver"", type any}, {""Invite Back"", type any}, {""Total Score"", Int64.T" & _
        "ype}, {""Notes"", type any}})" & Chr(13) & "" & Chr(10) & "in" & Chr(13) & "" & Chr(10) & "    #""Changed Type"""
    CurrentWorkbook.Connections.Add2 strName, _
    "Connection to the " & strName & "query in the workbook.", _
    "OLEDB;Provider=Microsoft.Mashup.OleDb.1;Data Source=$Workbook$;Location=" & strName & ";Extended Properties="_
  , "" & strName & "", 6, True, False

Where strName = InputBox("Enter Name")