简体   繁体   English

如何使用 python 和 selenium - 表单击此按钮

[英]How to click this button with python & selenium - table

url of the website 网站的网址

在此处输入图像描述

Hey all, I just wanna click this button with python my code:大家好,我只想用python我的代码点击这个按钮:

Main_page=webdriver.Chrome(options=chrome_options,service=chrome_service)
base_url="https://www.cbs.gov.il/he/Statistics/Pages/%D7%9E%D7%97%D7%95%D7%9C%D7%9C%D7%99%D7%9D/%D7%9E%D7%97%D7%95%D7%9C%D7%9C-%D7%AA%D7%90%D7%95%D7%A0%D7%95%D7%AA.aspx"
Main_page.get(base_url)
Main_page.maximize_window()
time.sleep(10)
button = Main_page.find_element(By.NAME, 'ישראל כולל יהודה ושומרון')
button.click()

i can figure it out why is not working我可以弄清楚为什么不工作

error: oSuchElementException: Message: no such element: Unable to locate element: {"method":"css selector","selector":"[name="ישראל כולל יהודה ושומרון"]"} (Session info: chrome=102.0.5005.63)错误:oSuchElementException:消息:没有这样的元素:无法找到元素:{"method":"css selector","selector":"[name="ישראל כולל יהודה ושומרון"]"} (会话信息:chrome=102.0. 5005.63)

check this article https://www.geeksforgeeks.org/click-element-method-selenium-python/检查这篇文章https://www.geeksforgeeks.org/click-element-method-selenium-python/

NOTE : you can also use xpath to find elements注意:您也可以使用 xpath 来查找元素

element = driver.find_element_by_xpath("//a[@id='link']")

NOTE : you can copy xpath from any Browser here is how to find xpath in browsers注意:您可以从任何浏览器复制 xpath这里是如何在浏览器中找到 xpath

button = Main_page.find_element(By.NAME, 'ישראל כולל יהודה ושומרון')
button.click()

you try to find elements by name , but שראל כולל יהודה ושומרון its not a valid html or xml name its an innerText of the button , try to find using xpath as i mentioned bef or find it by id您尝试按名称查找元素,但是שראל כולל יהודה ושומרון它不是有效的 html 或 xml 名称,它是按钮的内部文本,尝试使用我之前提到的 xpath 查找或通过 id 查找

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM