双击python selenium

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/17870528/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-19 09:21:43  来源:igfitidea点击:

Double clicking in python selenium

pythonseleniumdouble-click

提问by user2620763

I am using selenium with python. Im able to get the code below to click where I want but I want it to dbl click. Im not very good with the action chains and I know I need that for dbl click. Can anyone help with what I need to change around?

我在 python 中使用硒。我能够获得下面的代码以单击我想要的位置,但我希望它单击 dbl。我对动作链不太擅长,我知道我需要它来进行 dbl 点击。任何人都可以帮助我解决我需要改变的地方吗?

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

回答by Mahesh Reddy Atla

Action chains is the only best option as far i know

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

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()

回答by ard10n

try this:

尝试这个:

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()