简体   繁体   English

无法找到硒中的元素:{“方法”:“ css选择器”,“选择器”:“ [id =” identifierId”]”}

[英]Unable to locate element: {“method”:“css selector”,“selector”:“[id=”identifierId“]”} in selenium

I want to automate download to local and sent report (dashboard data studio) via email, but when I run the code in data studio , the chrome driver open, show notice "Report cannot be viewed at this time or does not have access" what should I do ? 我想通过电子邮件自动下载到本地并发送报告(仪表板数据工作室),但是当我在数据工作室中运行代码时,chrome驱动程序会打开,并显示“此时无法查看报告或无法访问报告”通知我该怎么办? here is my code: 这是我的代码:

# login to datastudio & refresh the newest data
self.chrome_driver.get(self.url)  
self.chrome_driver.find_element_by_id("identifierId").send_keys(self.email + u'\ue007')
self.quick_wait.until(EC.element_to_be_clickable((By.NAME, "password"))).send_keys(self.password+u'\ue007')
self.quick_wait.until(EC.element_to_be_clickable((By.XPATH, self.report_refresh))).click() # refresh report data
time.sleep(15)
# download file to local path
try:
    ActionChains(self.chrome_driver).context_click(self.chrome_driver.find_element_by_xpath(self.product_export)).perform()
    self.quick_wait.until(EC.element_to_be_clickable((By.XPATH, self.product_download))).click()
    time.sleep(20)
    self.quick_wait.until(EC.element_to_be_clickable((By.ID, self.report_download))).click()
    self.chrome_driver.find_element_by_css_selector(self.report_to_pdf).click()
    time.sleep(20)
except AssertionError as error:
    print(error)
    self.chrome_driver.quit()

i got error msg like: 我收到错误消息,例如:

selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: {"method":"css selector","selector":"[id="identifierId"]"}

enter image description here 在此处输入图片说明

enter image description here 在此处输入图片说明

enter image description here 在此处输入图片说明

enter image description here 在此处输入图片说明

Might be an issue with page load.try adding implicit or explicit wait. 页面加载可能是一个问题。尝试添加隐式或显式等待。

1.Apply required wait (implicit or explicit wait) 1.应用所需的等待(隐式或显式等待)

Implicit wait 隐式等待

driver.implicitly_wait(15)

Explicit wait: 显式等待:

wait = WebDriverWait(driver, 10)
wait.until(ec.visibility_of_element_located((By.XPATH, "//*[contains(@class,'result-list-entry')]")))

Example: 例:

self.chrome_driver.implicitly_wait(15)
self.chrome_driver.get(self.url)
self.quick_wait.until(EC.element_to_be_clickable((By.ID, "identifierId")))
self.chrome_driver.find_element_by_id("identifierId").send_keys(self.email + u'\ue007')
self.quick_wait.until(EC.element_to_be_clickable((By.NAME, "password"))).send_keys(self.password+u'\ue007')

2.Check whether element is a child of iframe element. 2.检查元素是否是iframe元素的子元素。 if so, switch to iframe and try to click 如果是这样,请切换至iframe并尝试点击

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 收到消息:没有这样的元素:无法找到元素:{"method":"css selector","selector":"[id="None"]"} Python 使用 selenium 时 - Getting Message: no such element: Unable to locate element: {"method":"css selector","selector":"[id="None"]"} Python when using selenium 使用 Selenium Python 选择下拉菜单 - 无法定位元素:{“method”:“css selector”,“selector”:"[id= - Selecting drop-down using Selenium Python - Unable to locate element: {“method”:“css selector”,“selector”:"[id= selenium.common.exceptions.NoSuchElementException:消息:没有这样的元素:无法找到元素:{“方法”:“css选择器”,“选择器”:“.ui流感~”} - selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: {"method":"css selector","selector":".ui flu~"} 消息:没有这样的元素:无法找到元素:{“method”:“css selector”,“selector”:“[id=”loginUsername“]”} - Message: no such element: Unable to locate element: {“method”:“css selector”,“selector”:“[id=”loginUsername“]”} Selenium NoSuchElementException-无法找到元素:{“方法”:“ css选择器”,“选择器”:“ [[名称=”电子邮件地址”]”} - Selenium NoSuchElementException - Unable to locate element: {“method”:“css selector”,“selector”:“[name=”emailAddress“]”} 没有这样的元素:无法定位元素:{“method”:“css selector”,“selector”:“[id=”guided-tour-tag-credentials-new“]”} - no such element: Unable to locate element: {“method”:“css selector”,“selector”:“[id=”guided-tour-tag-credentials-new“]”} NoSuchElementException:消息:没有这样的元素:无法找到元素:{"method":"css selector","selector":"[id="events_table"]"} - NoSuchElementException: Message: no such element: Unable to locate element: {"method":"css selector","selector":"[id="events_table"]"} 无法定位元素:{“method”:“css selector”,“selector”:“.Mr508”} - Unable to locate element: {“method”:“css selector”,“selector”:“.Mr508”} Python: Selenium 没有这样的元素: 无法定位元素: {“method”:“xpath”,“selector”:“//button[@data-id=1]”} - Python: Selenium no such element: Unable to locate element: {“method”:“xpath”,“selector”:“//button[@data-id=1]”} selenium 无法使用方法定位元素:无法通过 id、css_selector、xpath、链接文本找到元素 - selenium Unable to locate element using methods: cannot find elements by id, css_selector, xpath, link text
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM