英文:
Selenium unable to click button
问题
有一个按钮位于 https://mokivezi.lt/leidiniai 上,名为 "Open",您可以在目录图像下看到它。
它的元素是:
<button data-href="open" aria-label="Open UAB "Makveža" - Pagrindinis Moki-vezi kaininis leidinys">Open</button>
使用 Python Selenium 和 Edge/Chrome 的 web 驱动程序,我无法点击该按钮。
我尝试切换到不同的 iframe,但仍然出现附加的错误。
TimeoutException: Message:
我做错了什么?为了点击按钮,我尝试使用 WebDriverWait(driver, 5).until(EC.element_to_be_clickable((By.XPATH, "//button[text()='Open'])).click()
。
英文:
there is a button in https://mokivezi.lt/leidiniai called "Open" you can see it under catalog image.
It's element is:
<button data-href="open" aria-label="Open UAB &quot;Makveža&quot; - Pagrindinis Moki-vezi kaininis leidinys">Open</button>
Using Python Selenium and Edge/Chrome webdrivers, I am unable to click that button.
I tried switching to different iframe, but still getting attached error.
---------------------------------------------------------------------------
TimeoutException Traceback (most recent call last)
~\AppData\Local\Temp\ipykernel_1424836534134.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]
What wrong am I doing ? To click I tried using WebDriverWait(driver, 5).until(EC.element_to_be_clickable((By.XPATH, "//button[text()='Open']"))).click()
答案1
得分: 1
The Open
button is inside an iframe. you need to switch to iframe first, in order to access the element.
Use WebDriverWait()
and wait for frame_to_be_available_and_switch_to_it()
driver.get("https://mokivezi.lt/leidiniai")
WebDriverWait(driver, 10).until(EC.frame_to_be_available_and_switch_to_it((By.CSS_SELECTOR, "iframe[src='//view.publitas.com/uab-makveza/pagrindinis-moki-vezi_kedainiu_parduotuve/?publitas_embed=embedded']")))
openButton = WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.XPATH, "//button[text()='Open']"))
driver.execute_script("arguments[0].click();", openButton)
浏览器快照: 点击“打开”按钮后
英文:
The Open
button is inside an iframe. you need to switch to iframe first, in order to access the element.
Use WebDriverWait()
and wait for frame_to_be_available_and_switch_to_it()
driver.get("https://mokivezi.lt/leidiniai")
WebDriverWait(driver,10).until(EC.frame_to_be_available_and_switch_to_it((By.CSS_SELECTOR,"iframe[src='//view.publitas.com/uab-makveza/pagrindinis-moki-vezi_kedainiu_parduotuve/?publitas_embed=embedded']")))
openButton=WebDriverWait(driver,10).until(EC.element_to_be_clickable((By.XPATH,"//button[text()='Open']")))
driver.execute_script("arguments[0].click();", openButton)
Browser snapshot: After clicked on Open button
答案2
得分: 0
代码部分不要翻译,以下是翻译好的内容:
"The problem is that the element you are trying to click on doesn't exist."
"The element that displays 'Open' is this:"
<button data-href="open" aria-label="Open UAB "Makveža" - Pagrindinis Moki-vezi kaininis leidinys">
Open
</button>
"Try this possibly:"
WebDriverWait(driver, 5).until(EC.element_to_be_clickable((By.XPATH, "//button[text()='Open']"))).click()
英文:
The problem is that the element you are trying to click on doesn't exist
The element that displays "Open" is this
<button data-href="open" aria-label="Open UAB &quot;Makveža&quot; - Pagrindinis Moki-vezi kaininis leidinys">
Open
</button>
try this possibly
WebDriverWait(driver, 5).until(EC.element_to_be_clickable((By.XPATH, "//button[text()='Open']"))).click()
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论