【发布时间】:2022-09-24 08:45:28
【问题描述】:
我希望有人可以帮助我更好地理解,所以到目前为止我一直引用的网站是https://selenium-python.readthedocs.io/locating-elements.html#locating-elements-by-css-selectors
这是代码(它确实有效)
#https://www.softwaretestinghelp.com/selenium-python-tutorial/#Configuration_Of_Selenium_In_PyCharm
import time
from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.common.by import By
serv = Service(r\"C:\\Users\\BAtMAn\\PycharmProjects\\DellUpdate\\Drivers\\chromedriver.exe\")
driver = webdriver.Chrome(service=serv)
driver.get(\"https://www.dell.com/support\")
driver.maximize_window()
def Step1():
SearchBar = driver.find_element(By.NAME, \"entry-main-input-home\").send_keys(\"Test\")
SearchBarClick = driver.find_element(By.ID,\"txtSearchEs\").click()
Step1()
def Popup():
if driver.find_element(By.ID, \"sec-overlay\"):
time.sleep(30.5)
SearchBarClick = driver.find_element(By.ID, \"txtSearchEs\").click()
time.sleep(5)
Popup()
def FeedBack():
if driver.find_element(By.CSS_SELECTOR, (\'<button id=\"noButtonIPDell\" class=\"noButton buttons\" aria-label=\"No, thanks\">No, thanks</button>)\'):
driver.find_element(By.ID, \"button id#noButtonIPDell\").click()
FeedBack()
def Drivers():
if FeedBack() == False:
driver.find_element(By.ID, \"drivers\").click()
Drivers()
我的问题是我在找到一个有效的 ID 和 Class_NAME 之前经历了一堆,我想知道是不是我只是不明白我在读什么。下面是我尝试的 class_name 和 ID 的列表,但 driver.find_element 没有找到任何东西。
班级名称, \”\”):自定义 Aka-popup-body 区域 aka-popup-text-center aka-popup-margin-bottom24 自定义-Aka-popup-icon
IDes-alert-notice-duotone 秒覆盖
好的,所以我正在检查的是我不断收到的 30 秒延迟弹出窗口 dell.com/support 弹出窗口似乎只在运行代码时出现,而不是在我手动拉起所有内容时出现。
(最新版本 8/24 3pm gmt-4) 错误(不单击“查找驱动程序下拉菜单”)
selenium.common.exceptions.NoSuchElementException:消息:没有这样的元素:无法找到元素:{\"method\":\"xpath\",\"selector\":\"//iframe[@title=\'Dell民意调查\']\”}
# https://www.softwaretestinghelp.com/selenium-python-tutorial/#Configuration_Of_Selenium_In_PyCharm
\"\"\"
Pip Installs:
Selenium
\"\"\"
import pyautogui
import time
import subprocess
import pyperclip
import re
from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.common.by import By
serv = Service(r\"C:\\Users\\rcowart\\Desktop\\Robert\\Pycharm\\DellUpdate - selenium\\Driver\\chromedriver.exe\")
driver = webdriver.Chrome(service=serv)
driver.get(\"https://www.dell.com/support\")
driver.maximize_window()
def SerialNumber():
SerialNumber = \'wmic bios get serialnumber\'
result = subprocess.getoutput(SerialNumber)
SerialResult = (result.strip(\"SerialNumber\"))
print(re.sub(\"[^a-zA-Z0-9]+\", \"\", SerialResult))
pyperclip.copy(re.sub(\"[^a-zA-Z0-9]+\", \"\", SerialResult))
SerialNumber()
def Step1():
SearchBar = driver.find_element(By.NAME, \"entry-main-input-home\").send_keys(\"3Q84KQ2\")
SearchBarClick = driver.find_element(By.ID,\"txtSearchEs\").click()
print(\"Locating SerialNumber\")
Step1()
def Popup():
#30 second popup
if driver.find_element(By.ID, \"sec-overlay\"):
time.sleep(30.5)
driver.find_element(By.ID, \"txtSearchEs\").click()
print(\"Searching: \")
else:driver.find_element(By.ID,\"txtSearchEs\").click()
time.sleep(3)
Popup()
def DriversAndDownloads():
#refresh bypasses the FeedBack not being found
pyautogui.press(\"f5\")
if driver.find_element(By.ID, \"drivers\"):
driver.find_element(By.ID, \"drivers\").click()
print(\"Successfully Located DriversAndDownloads\")
else:
pyautogui.press(\"f5\")
driver.find_element(By.ID, \"drivers\").click()
print(\"Refreshing page!\")
def FeedBack():
#popup asking for feedback
if driver.find_elements(By.ID, \"noButtonIPDell\"):
driver.find_element(By.ID, \"noButtonIPDell\").click()
print(\"Sucessfully Located FeedBack: ID\")
else:
#sleep gives DriversAndDownloads time to refresh/find element without the popup covering it
print(\"Unable to locate FeedBack!\")
pyautogui.press(\'f5\')
time.sleep(3)
DriversAndDownloads()
FeedBack()
def FindDrivers():
#Drop down
if driver.find_element(By.XPATH, \"//iframe[@title=\'Dell Survey\']\"):
driver.find_element(By.XPATH, \"//iframe[@title=\'Dell Survey\']\").click()
print(\"Successfully located FindDrivers: iframe: Dell Survey\")
elif driver.switch_to.frame(\"iframeSurvey\"):
driver.find_element(By.ID, \"iframeSurvey\").click()
print(\"Successfully located FindDrivers: iframeSurvey\")
else:
print(\"Unable to locate FindDrivers\")
FindDrivers()
-
仍然在尝试让 ID 进行下一步工作时遇到问题。感谢您提供任何帮助来解决这个问题。
-
这听起来像X-Y problem。与其寻求解决问题的帮助,不如编辑您的问题并询问实际问题。你想做什么?
-
@undetectedSelenium 我正在尝试检查一些网页上的元素。目前我已经创建了一个函数来检查是否弹出一个 .. 弹出,如果是,请单击否。所以(在 chrome 中)弹出窗口我右键单击 \"no\" 框并检查,它返回<button id=\"noButtonIPDell\" class=\"noButton buttons\" aria-label=\"不,谢谢\">不,谢谢</button>我尝试使用一些选项,但driver.find_element(By.CSS_SELECTOR, (\'<button id=\"noButtonIPDell\" class=\"noButton buttons\" aria-label=\"不,谢谢\">不,谢谢</button>)\' )和 ** driver.find_element(By.ID, \"button id#noButtonIPDell\")*
-
不知何故,我无法重现不,谢谢按钮。使用手动步骤更新问题。
-
@undetectedSelenium 它要求您使用实际的戴尔序列号(不会每次都弹出,但大部分时间)我将包含(我假设)Html 的图像
标签: python python-3.x selenium classname