selenium 我可以知道为什么它显示无法定位元素吗?

m4pnthwp  于 2023-01-20  发布在  其他
关注(0)|答案(1)|浏览(184)
from selenium import webdriver  
import time
from selenium.webdriver.common.keys import Keys  
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait

driver = webdriver.Chrome('ChromeDriver')
driver.get("https://devbusiness.tunai.io/login")
time.sleep(2)
driver.maximize_window()

#log in credentials
username = driver.find_element(By.NAME, "loginUsername");
username.send_keys("kevin@tunai");

password = driver.find_element(By.NAME, "loginPassword");
password.send_keys("123456");

login = driver.find_element(By.XPATH,"//*[@id='app']/div/div/div/div/div/div[2]/form/div[4]/button");
login.submit();
time.sleep(3)

driver.get("https://devbusiness.tunai.io/dashboard/salon_report_voucher")
time.sleep(3)

driver.find_element(By.XPATH, '//*[@id="packageTable"]/tbody[1]/tr/td[1]').click()
time.sleep(2)

driver.find_element(By.XPATH,'//*[@id="packageTable"]/tbody[1]/tr').click()
time.sleep(2)

#trigger the element before click
voucher = driver.find_element(By.XPATH, "//*[@id='packageTable']/tbody[2]/tr[1]")
driver.execute_script("arguments[0].click();", voucher)
time.sleep(2)
driver.find_element(By.XPATH, '//*[@id="packageTable"]/tbody[2]/tr[1]')
time.sleep(2)

#trigger the detail button
detail = driver.find_element(By.XPATH, "//*[@id='checkAll']")
driver.execute_script("arguments[0].click();", detail)
time.sleep(5)
driver.find_element(By.XPATH, "//*[@id='checkAll']")
time.sleep(5)

driver.find_element(By.XPATH, '//*[@id="voucherModal___BV_modal_body_"]/div/div/button[1]').click()
time.sleep(5)

我想点击编辑新价格并输入一个新价格,保存并循环它。现在,我不允许输入新价格并继续。我复制了Xpath并尝试,但失败了,所以我认为是因为弹出页面。这就是失败的原因。

dgjrabp2

dgjrabp21#

要单击Edit Price按钮,请使用webdriverwait()并等待元素可单击并跟随xpath
然后等待模型弹出,然后输入值。

WebDriverWait(driver,10).until(EC.element_to_be_clickable((By.XPATH,"//div[@id='voucherModal___BV_modal_content_']//button[text()='Edit Price']"))).click()
WebDriverWait(driver,10).until(EC.element_to_be_clickable((By.XPATH,"//div[@id='voucherEditModal___BV_modal_content_']//input[@data-maska-tokens]"))).click()    
WebDriverWait(driver,10).until(EC.element_to_be_clickable((By.XPATH,"//div[@id='voucherEditModal___BV_modal_content_']//input[@data-maska-tokens]"))).send_keys("1000")

你需要导入下面的库.

from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.support.ui import WebDriverWait

相关问题