Draco D
Draco D

Reputation: 334

Python is not recognising the button to click with Selenium

So I am currently trying to scrape data from youtube pages. I am using Selenium in order to do this automatically. The issue is that the browser that comes up has not signed in as I am on the non generated selenium browser. So it comes up with the sign in or 'No Thanks' icon. I have looked around and found the Xpath for the 'No Thanks' button but my system indicates 'element not interactable'.

Xpath of the button: enter image description here

Code I inputted:

enter image description here

#We need to tell the drive to find the video of choice
driver.find_element_by_xpath('//*[@id="video-title"]')
driver.find_element_by_xpath('//*[@id="button"]')

#Interact with the above
driver.find_element_by_xpath('//*[@id="video-title"]').click()
driver.find_element_by_xpath('//*[@id="button"]').click()

I tried to copy the full Xpath also. Any suggestions?

Upvotes: 1

Views: 262

Answers (1)

Draco D
Draco D

Reputation: 334

So, after nearly a whole day, I came up with a simple fix.

Could not quite find the xpath or id or name of the pop-up. But if I reload the page, it does not show up again.

So a simple

driver.refresh()

or

driver.get(driver.current_url)

should work after you click on your link.

Issue - another iframe object pops up, the google cookies. I tried deleting all cookies but it still loads. I also tried other ways of getting into the iframe and then clicking on the button to no avail. But the link below helped with this (the second answer):

Youtube google popup - selenium

Thanks!

Upvotes: 1

Related Questions