Eden Sh
Eden Sh

Reputation: 27

How to click this button with python & selenium - table

url of the website

enter image description here

Hey all, I just wanna click this button with python my code:

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)

Upvotes: 1

Views: 169

Answers (2)

rusty
rusty

Reputation: 73

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

Upvotes: 2

rusty
rusty

Reputation: 73

check this article https://www.geeksforgeeks.org/click-element-method-selenium-python/

NOTE : you can also use xpath to find elements

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

Upvotes: 2

Related Questions