[英]Selenium Python automation - Cannot find upload button/input type="file"
[英]Find the button element for selenium Automation in python
我检查了元素并得到了以下代码。
这个“激活”按钮在 4 小时内只出现一次。 要运行该过程,我需要找到这个元素。
我尝试使用:
find_element_by_class_name
find_element_by_link_text
<div class="wrapper">
<button class="w-full h-14 pt-2 pb-1 px-3 bg-accent text-dark-1 rounded-full md:rounded select-none cursor-pointer md:hover:shadow-big focus:outline-none md:focus:bg-accent-2 md:focus:shadow-small ">
<div class="font-medium">
<div class="text-17 md:text-18 md:font-bold leading-18">Activate</div>
<div class="text-13 md:text-12 font-normal md:font-medium leading-normal">to run process</div></div>
</button>
</div>
这应该搜索并刷新页面,直到弹出一个元素。
wait = WebDriverWait(driver, 30)
while True:
try:
wait.until(EC.presence_of_element_located((By.XPATH,"//div[@class='wrapper']/div[.='Activate']")))
break
except:
driver.refresh()
进口
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
我对那个特定的网站也有同样的问题,我终于能够解决它。 我所做的是通过 Chromes 检查元素工具找到网站的“iframe”。
您可以在此处找到 iframe 源代码:
一旦发现这一点,请编写以下代码:
while True:
try:
self.driver.get("Enter Iframe src here")
time.sleep(4)
self.driver.find_element(By.CSS_SELECTOR, ".wrapper > .w-full").click()
break
except NoSuchElementException:
self.driver.refresh()
time.sleep(10)
请注意,通过动态获取 iframe src 可能有更好的方法。 但这应该有效。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.