Double clicking in python selenium

寵の児 提交于 2019-12-18 16:47:13

问题


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?

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

回答1:


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



回答2:


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


来源:https://stackoverflow.com/questions/17870528/double-clicking-in-python-selenium

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!