【问题标题】:Double clicking in python selenium双击python selenium
【发布时间】:2013-07-26 02:01:41
【问题描述】:

我在 python 中使用 selenium。我能够获取下面的代码以单击我想要的位置,但我希望它能够单击。我对动作链不是很好,我知道我需要 dbl click。任何人都可以帮忙解决我需要改变的地方吗?

user = self.find_element_by_id("selUsers")
for option in user.find_elements_by_tag_name("option"):
    if option.text == "Admin, Ascender":
         option.click()

【问题讨论】:

    标签: python selenium double-click


    【解决方案1】:

    据我所知,动作链是唯一的最佳选择

    from selenium.webdriver.common.action_chains import ActionChains
    
    driver=self.webdriver
    user = self.find_element_by_id("selUsers")
    for option in user.find_elements_by_tag_name("option"):
       if option.text == "Admin, Ascender":
          actionChains = ActionChains(driver)
          actionChains.double_click(option).perform()
    

    【讨论】:

      【解决方案2】:

      试试这个:

      from selenium import webdriver
      from selenium.webdriver.support.ui import WebDriverWait
      from selenium.webdriver.support import expected_conditions as EC
      from selenium.webdriver.common.by import By
      from time import sleep
      from selenium.webdriver.common.keys import Keys
      from selenium.webdriver.common.action_chains import ActionChains
      
      usernameStr = 'xxxxxx'
      passwordStr = 'xxxxx'
      
      browser = webdriver.Chrome()
      browser.get(('https://accounts.google.com/ServiceLogin?'
               'service=mail&continue=https://mail.google'
               '.com/mail/#identifier'))
      
      
      username = browser.find_element_by_id('identifierId')
      username.send_keys(usernameStr)
      nextButton = browser.find_element_by_id('identifierNext')
      
      nextButton.click()
      
      # wait for transition then continue to fill items
      password = WebDriverWait(browser, 10).until(EC.presence_of_element_located((By.XPATH,'//*    [@id="password"]/div[1]/div/div[1]/input')))
      
      password.send_keys(passwordStr)
      
      signInButton = browser.find_element_by_id('passwordNext')
      signInButton.click()
      
      apsButton = WebDriverWait(browser, 10).until(EC.presence_of_element_located((By.XPATH,'//[@id="gbwa"]/div/a')))
      
      apsButton.click()
      driveButton = WebDriverWait(browser, 10).until(EC.presence_of_element_located((By.XPATH,'//*[@id="gb49"]/span[1]')))
      driveButton.click()
      

      【讨论】:

        猜你喜欢
        • 2017-08-09
        • 1970-01-01
        • 2015-01-10
        • 1970-01-01
        • 2014-09-05
        • 1970-01-01
        • 1970-01-01
        • 2021-12-26
        • 1970-01-01
        相关资源
        最近更新 更多