gpt4 book ai didi

python - 单击由 JavaScript 使用 Python Webdriver 编写的数据绑定(bind)下的按钮

转载 作者:行者123 更新时间:2023-12-01 07:34:36 25 4
gpt4 key购买 nike

我可以登录网站,但不知道如何点击“下载为 CSV”。我尝试过 XPATH 和 CSS 选择器。

这是 HTML 的图片。 enter image description here

仪表板与许多小部件结合在一起。不知道这是否会影响什么。 enter image description here如果您需要更多信息,请告诉我。谢谢:)

下面是代码

from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.support.select import Select
from selenium.webdriver.common.action_chains import ActionChains
import time

#### location of chrome
driver = webdriver.Chrome(r'F:\User\Downloads\chromedriver.exe')

#### log in website 1
driver.get('https://www.yardipca.com/39444siteminderlive/')

### 1st door ( login& password)
name_1st = driver.find_element_by_name('USER')
name_1st.clear()
name_1st.send_keys('my_account')

passowrd_1st = driver.find_element_by_name('PASSWORD')
passowrd_1st.clear()
passowrd_1st.send_keys('my_password')

### login botton
WebDriverWait(driver, 30).until(EC.element_to_be_clickable((By.XPATH,"/html/body/form/div/center/table[2]/tbody/tr[3]/td[2]/table/tbody/tr[8]/td[2]/input[6]"))).click()
WebDriverWait(driver, 30).until(EC.element_to_be_clickable((By.LINK_TEXT,"P260 Live System (SAN/HOC)"))).click()
WebDriverWait(driver, 30).until(EC.element_to_be_clickable((By.XPATH, '//*[@id="acceptButton"]'))).click()

time.sleep(10)




#### log in website 2
driver.get('https://www.yardiasptx11.com/39444p260livehoc/jsp/index.jsp')

### 2nd door ( login& password)
name_2nd = driver.find_element_by_name('userId')
name_2nd.send_keys('my_account')

passowrd_2nd = driver.find_element_by_name('password')
passowrd_2nd.send_keys('my_password')

### login botton
WebDriverWait(driver, 30).until(EC.element_to_be_clickable((By.XPATH, '//[@id="standardLoginForm"]/div[3]/button'))).click()
time.sleep(5)

### Dropdown button
WebDriverWait(driver, 30).until(EC.element_to_be_clickable((By.XPATH, '//*[@id="widget_937242"]/div[1]/div[1]'))).click()

# //*[@id="widget_937242"]/div[1]/div[1]
# //*[@id="widget_937242"]/div[1]/div[1]/a
# //*[@id="widget_937242"]/div[1]/div[1]/a/span

### download file
WebDriverWait(driver, 30).until(EC.element_to_be_clickable((By.CSS_SELECTOR,'#widget_937242 > div.panel-heading.ui-sortable-handle > div.btn-group.pull-right.print-hide.open > ul > li:nth-child(2) > a'))).click()



time.sleep(10)

弹出错误。

文件“f:\User\Downloads\yardi.py”,第 57 行,位于

WebDriverWait(driver, 30).until(EC.element_to_be_clickable((By.XPATH, '//*[@id="widget_937242"]/div 1/div 1 '))).click( )

文件“F:\Anaconda3\lib\site-packages\selenium\webdriver\support\wait.py”,第 80 行,直到引发 TimeoutException(消息、屏幕、堆栈跟踪)selenium.common.exceptions.TimeoutException:消息:

最佳答案

看起来小部件总是在同一个位置,如果您在 Windows 上运行它,我通常会尝试使用 X/Y 坐标与 AppRobotic 等宏工具进行单击。如果这是页面加载缓慢的问题,我通常会尝试停止页面加载,并与页面进行一些交互,这样的操作应该适合您:

import win32com.client
from win32com.client import Dispatch
x = win32com.client.Dispatch("AppRobotic.API")
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC

driver = webdriver.Chrome('chromedriver.exe')
driver.get('https://www.google.com')
# wait 20 seconds
x.Wait(20000)
# scroll down a couple of times in case page javascript is waiting for user interaction
x.Type("{DOWN}")
x.Wait(2000)
x.Type("{DOWN}")
x.Wait(2000)
# forcefully stop pageload at this point
driver.execute_script("window.stop();")
# if clicking Download as CSV button with Selenium still does not work here, use screen coordinates
x.MoveCursor(xCoord, yCoord)
x.MouseLeftClick
x.Wait(2000)

关于python - 单击由 JavaScript 使用 Python Webdriver 编写的数据绑定(bind)下的按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57046606/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com