【发布时间】:2022-08-04 03:03:43
【问题描述】:
我正在尝试使网站自动化以自动制作用户配置文件。遇到了我无法选择的 NG 按钮。我尝试过 XPATH、CSS 和类名。这些似乎都不起作用。我不断收到“NoSuchElementException”:
By.XPATH, \'//button[normalize-space()=\"Create New User\"]\'
和
By.CSS_SELECTOR, \'.newUser.ng-scope\'
当我尝试使用 Webdriverwait 时,出现超时错误。
代码试验:
import time
from webbrowser import Chrome
from xml.etree.ElementPath import find
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.support.ui import WebDriverWait
driver = webdriver.Chrome()
driver.get(\'https://power.dat.com\')
chrome_optinons = webdriver.ChromeOptions()
chrome_optinons.add_argument(\'--headless\')
chrome_optinons.add_argument(\'window-size=1920x1080\')
username = driver.find_element(By.XPATH, \'//*[@id=\"mat-input-1\"]\')
username.send_keys(\'\')
password = driver.find_element(By.XPATH, \'//*[@id=\"mat-input-0\"]\')
password.send_keys(\'\')
#(time.sleep(3))
loginbutton = driver.find_element(By.XPATH, \'//*[@id=\"submit-button\"]\')
loginbutton.click()
(time.sleep(5))
profiledrop = driver.find_element(By.XPATH, \'//*[@id=\"user-salutation\"]\')
profiledrop.click()
Adminbutton = driver.find_element(By.CSS_SELECTOR, \'#userPreferencesUl > li:nth-child(5) > a\')
Adminbutton.click()
# (time.sleep(10))
NewUsrBtn = driver.find_element(By.XPATH, \'//button[normalize-space()=\"Create New User\"]\')
NewUsrBtn.click()
#WebDriverWait(driver , 10).until(EC.element_to_be_clickable((By.CSS_SELECTOR, \'.newUser.ng-scope\'))).click()`
的HTML
<button class=\"newUser ng-scope\" type=\"button\" ng-if=\"isTrustedAdmin()\" ng-click=\"onNewUser();\" ng-disabled=\"user.isInEditMode\">
Create New User
</button>
如果需要,我还附上了更多 HTML 的屏幕截图
-
//button[text()=\"Create New User\"] is this working?
-
不,我得到了 TimeOutException
标签: python selenium xpath css-selectors webdriverwait