https://mokivezi.lt/leidiniai中有一个名为“打开”的按钮,您可以在目录图像下看到它。
它的要素是:<button data-href="open" aria-label="Open UAB "Makveža" - Pagrindinis Moki-vezi kaininis leidinys">Open</button>
使用Python Selenium和Edge/Chromewebdrivers时,我无法单击该按钮。我尝试切换到不同的iframe,但仍会出现附加错误。
---------------------------------------------------------------------------
TimeoutException Traceback (most recent call last)
~\AppData\Local\Temp\ipykernel_14248\1636534134.py in <module>
----> 1 WebDriverWait(driver, 5).until(
2 EC.element_to_be_clickable((By.XPATH, "//button[text()='Open']"))
3 ).click()
~\Anaconda3\envs\webscraping\lib\site-packages\selenium\webdriver\support\wait.py in until(self, method, message)
93 if time.monotonic() > end_time:
94 break
---> 95 raise TimeoutException(message, screen, stacktrace)
96
97 def until_not(self, method, message: str = ""):
TimeoutException: Message:
Stacktrace:
Backtrace:
Microsoft::Applications::Events::EventProperties::SetProperty [0x00007FF7262B16C2+15186]
Microsoft::Applications::Events::EventProperty::EventProperty [0x00007FF72624A212+827554]
(No symbol) [0x00007FF725F0ED90]
(No symbol) [0x00007FF725F52225]
(No symbol) [0x00007FF725F523AC]
(No symbol) [0x00007FF725F8E087]
(No symbol) [0x00007FF725F71F8F]
(No symbol) [0x00007FF725F44C3E]
(No symbol) [0x00007FF725F8B513]
(No symbol) [0x00007FF725F71D23]
(No symbol) [0x00007FF725F43B80]
(No symbol) [0x00007FF725F42B0E]
(No symbol) [0x00007FF725F44344]
Microsoft::Applications::Events::EventProperties::SetProperty [0x00007FF72612C3B0+182752]
(No symbol) [0x00007FF726000095]
Microsoft::Applications::Events::EventProperty::EventProperty [0x00007FF72618A6EA+42362]
Microsoft::Applications::Events::EventProperty::EventProperty [0x00007FF72618D425+53941]
Microsoft::Applications::Events::ILogManager::DispatchEventBroadcast [0x00007FF7264A8AB3+1456595]
Microsoft::Applications::Events::EventProperty::EventProperty [0x00007FF72625276A+861690]
Microsoft::Applications::Events::EventProperty::EventProperty [0x00007FF726257854+882404]
Microsoft::Applications::Events::EventProperty::EventProperty [0x00007FF7262579AC+882748]
Microsoft::Applications::Events::EventProperty::EventProperty [0x00007FF72626097E+919566]
BaseThreadInitThunk [0x00007FFF40C77AD4+20]
RtlUserThreadStart [0x00007FFF436CA371+33]
我做错了什么?要单击,我尝试使用WebDriverWait(driver, 5).until(EC.element_to_be_clickable((By.XPATH, "//button[text()='Open']"))).click()
3条答案
按热度按时间ewm0tg9j1#
Open
按钮位于iframe中。您需要先切换到iframe,才能访问元素。使用
WebDriverWait()
并等待frame_to_be_available_and_switch_to_it()
**浏览器快照:**单击“打开”按钮后
kr98yfug2#
问题是您尝试单击的元素不存在
显示“Open”的元素如下
不妨试试这个
vltsax253#
你可以用pyautogui来做。只要修改坐标。