Python 3.x selenium webdriver click事件不适用于从select2下拉列表中选择的选项
selenium webdriver click事件不适用于从select2下拉列表中选择的选项Python 3.x selenium webdriver click事件不适用于从select2下拉列表中选择的选项,python-3.x,selenium-webdriver,ui-automation,Python 3.x,Selenium Webdriver,Ui Automation,selenium webdriver click事件不适用于从select2下拉列表中选择的选项 sel_advertiser = Select(self.driver.find_element_by_id("brand_option")) for option in sel_advertiser.options: name = str(option.get_attribute("text")) if name == advertiser_name: print "Found adver
sel_advertiser = Select(self.driver.find_element_by_id("brand_option"))
for option in sel_advertiser.options:
name = str(option.get_attribute("text"))
if name == advertiser_name:
print "Found advertiser"
option.click()
在这种情况下,如果我传递了正确的广告客户名称,那么它将打印广告客户发现。但不是从下拉列表中选择相同的广告客户。点击后基本上什么都没有发生
你能让我知道我错过了什么吗
谢谢。实际上没问题。 webdriver无法刷新下拉列表
sel_advertiser = Select(self.driver.find_element_by_id("brand_option"))
for option in sel_advertiser.options:
name = str(option.get_attribute("text"))
if name == advertiser_name:
print "Found advertiser"
option.click()
您可以看到您的下拉列表选项被选中的最佳方式是编写以下内容
option.submit();
不是refresh()
,而是submit()
PS:我也遇到了同样的问题,我需要发送表单来刷新下拉列表和所有复选框。实际上没有问题。 webdriver无法刷新下拉列表
sel_advertiser = Select(self.driver.find_element_by_id("brand_option"))
for option in sel_advertiser.options:
name = str(option.get_attribute("text"))
if name == advertiser_name:
print "Found advertiser"
option.click()
您可以看到您的下拉列表选项被选中的最佳方式是编写以下内容
option.submit();
不是refresh()
,而是submit()
PS:我也遇到了同样的问题,我需要发送表单来刷新下拉列表和所有复选框。我必须使用ActionChains类移动到元素a,然后单击。然后Select2元素将在Firefox和PhantomJS中打开。它在Chrome中没有这种黑客攻击,但我需要PhantomJS支持
from selenium.webdriver.common.action_chains import ActionChains
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
#Click on the element to open the dropdown
el = driver.find_element_by_id('id_to_element')
actions = ActionChains(driver)
actions.move_to_element(el)
actions.click()
actions.perform()
#Click on the correct item within the dropdown, waiting for it to load
item_to_select = 'Some text in select'
xpath = '//div[@class="select2-result-label" and' +\
' text()[contains(.,"%s")]]' % (item_to_select)
wait = WebDriverWait(driver, 10)
elm = wait.until(
EC.element_to_be_clickable(
(
By.XPATH,
xpath
)
),
'waiting for %s to be clickable' % (xpath)
)
elm.click()
我必须使用ActionChains类移动到元素a,然后单击。然后Select2元素将在Firefox和PhantomJS中打开。它在Chrome中没有这种黑客攻击,但我需要PhantomJS支持
from selenium.webdriver.common.action_chains import ActionChains
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
#Click on the element to open the dropdown
el = driver.find_element_by_id('id_to_element')
actions = ActionChains(driver)
actions.move_to_element(el)
actions.click()
actions.perform()
#Click on the correct item within the dropdown, waiting for it to load
item_to_select = 'Some text in select'
xpath = '//div[@class="select2-result-label" and' +\
' text()[contains(.,"%s")]]' % (item_to_select)
wait = WebDriverWait(driver, 10)
elm = wait.until(
EC.element_to_be_clickable(
(
By.XPATH,
xpath
)
),
'waiting for %s to be clickable' % (xpath)
)
elm.click()
sel_广告客户。sel_by_visible_文本(“广告客户名称”)也不工作。sel_广告客户。sel_by_visible_文本(“广告客户名称”)也不工作。谢谢。如果我尝试这样做,我会得到“InvalidElementStateException:Message:u'Element未在表单中,因此无法提交”错误。谢谢。如果我尝试这样做,我会得到“InvalidElementStateException:Message:u”元素不在表单中,因此无法提交”错误。