如何使用python selenium从google表单下拉菜单中选择内容只有divs没有选择标记

2024-09-25 00:20:55 发布

您现在位置:Python中文网/ 问答频道 /正文

这是表单链接:https://docs.google.com/forms/d/e/1FAIpQLSe61r6TNx4JvRg2gVu3Eu8-KYKCvd1dJCAmYJFnNw4EU9llMw/viewform这是我的代码我想选择DHAOUI MOHAMED AZIZ我缺少什么:

import time
from selenium import webdriver

def sleep():
    time.sleep(5)

Chrome = webdriver.Chrome(executable_path='C:/Users/dhaou/Desktop/chromedriver.exe')
url = "https://docs.google.com/forms/d/e/1FAIpQLSe61r6TNx4JvRg2gVu3Eu8-KYKCvd1dJCAmYJFnNw4EU9llMw/viewform"
Chrome.get(url)
first_div = Chrome.find_element_by_xpath('//*[@id="mG61Hd"]/div[2]/div/div[2]/div[1]/div/div/div[2]/div')
first_div.click()
sleep()
second=Chrome.find_element_by_xpath('//*[@id="mG61Hd"]/div[2]/div/div[2]/div[1]/div/div/div[2]/div/div[1]/div[1]/div[16]')
second.click()

Tags: httpsimportdivcomurldocstimegoogle
1条回答
网友
1楼 · 发布于 2024-09-25 00:20:55

对于您提供的url,这似乎对我有用

PATH = "./chromedriver"

driver = webdriver.Chrome(PATH)
driver.implicitly_wait(5)

url = "https://docs.google.com/forms/d/e/1FAIpQLSe61r6TNx4JvRg2gVu3Eu8-KYKCvd1dJCAmYJFnNw4EU9llMw/viewform"
driver.get(url)

element = ".quantumWizMenuPaperselectOption.appsMaterialWizMenuPaperselectOption.freebirdThemedSelectOptionDarkerDisabled.exportOption.isSelected.isPlaceholder"

dropdown = driver.find_element_by_css_selector(element)
dropdown.click()

name = "ALI GHANMI"
list_element = "//div[@class='exportSelectPopup quantumWizMenuPaperselectPopup appsMaterialWizMenuPaperselectPopup']//span[text()='"+name+"']"

dropdown_element = driver.find_element_by_xpath(list_element)
dropdown_element.click()

顺便说一下,您提供的URL中的表单没有DHAOUI MOHAMED AZIZ。我试了一个不同的名字

相关问题 更多 >