Select2 - 在没有库函数的情况下单击触发器打开

时间:2017-06-07 06:18:06

标签: javascript jquery jquery-select2

我正在使用此库:https://select2.github.io

当您使用此库并且要强制以编程方式打开选择菜单时,请运行以下命令:

09:22:53.149 INFO - Launching a standalone Selenium Server
Setting system property webdriver.chrome.driver to C:\dev\selenium\chromedriver.exe
Setting system property webdriver.chrome.binary to C:\dev\selenium\chrome-win32\chrome.exe
Setting system property webdriver.chrome.chrome_binary to C:\dev\selenium\chrome-win32\chrome.exe
Setting system property webdriver.chrome.capabilities.binary to C:\dev\selenium\chrome-win32\chrome.exe
Setting system property webdriver.chrome.capabilities.chrome_binary to C:\dev\selenium\chrome-win32\chrome.exe
09:22:53.480 INFO - Java: Oracle Corporation 25.65-b01
09:22:53.480 INFO - OS: Windows 7 6.1 amd64
09:22:53.490 INFO - v2.53.1, with Core v2.53.1. Built from revision a36b8b1
09:22:53.569 INFO - Driver class not found: com.opera.core.systems.OperaDriver
09:22:53.569 INFO - Driver provider com.opera.core.systems.OperaDriver is not registered
09:22:53.579 INFO - Driver provider org.openqa.selenium.safari.SafariDriver registration is skipped:
registration capabilities Capabilities [{browserName=safari, version=, platform=MAC}] does not match the current platform VISTA
09:22:53.579 INFO - Driver class not found: org.openqa.selenium.htmlunit.HtmlUnitDriver
09:22:53.579 INFO - Driver provider org.openqa.selenium.htmlunit.HtmlUnitDriver is not registered
09:22:53.928 INFO - RemoteWebDriver instances should connect to: http://127.0.0.1:4444/wd/hub
09:22:53.928 INFO - Selenium Server is up and running
09:22:54.331 INFO - Executing: [new session: Capabilities [{acceptSslCerts=false, browserName=chrome, platform=ANY}]])
09:22:54.345 INFO - Creating a new session for Capabilities [{acceptSslCerts=false, browserName=chrome, platform=ANY}]
Starting ChromeDriver 2.24.417431 (9aea000394714d2fbb20850021f6204f2256b9cf) onport 4923
Only local connections are allowed.
09:22:55.137 INFO - Done: [new session: Capabilities [{acceptSslCerts=false, browserName=chrome, platform=ANY}]]

并打开选择菜单。

但是如果你跑:

$('#fromAccIdx').select2('open');

模拟打开菜单的点击,它不能像使用鼠标一样在这个元素上工作。

我想知道如何在不使用库本身的$('#fromAccIdx').click(); 功能的情况下打开选择菜单。

有可能吗?

1 个答案:

答案 0 :(得分:-1)

试试这个。它有效。

 document.getElementById("fromAccIdx").click();

而不是$('#fromAccIdx')。click();