'how to click on pop up elements using undetected chromedriver
i am trying to make 5-star bot i have already done half work for getting login with gmail only place i am stuck is when it come to clicking on pop up window asking for starts and writing review i can't even click on cancel button.The pop up appears to be inside another iframe (#document)
My code
import time
import undetected_chromedriver as uc
from selenium.webdriver.common.keys import Keys
def login_Undetected():
username = '[email protected]'
password ='ABC'
driver = uc.Chrome()
driver.get('https://accounts.google.com/ServiceLogin')
time.sleep(2)
driver.find_element_by_xpath('//input[@type="email"]').send_keys(username)
time.sleep(2)
driver.find_element_by_xpath('//*[@id="identifierNext"]').click()
time.sleep(2)
driver.find_element_by_xpath('//input[@type="password"]').send_keys(password)
time.sleep(2)
driver.find_element_by_xpath('//*[@id="passwordNext"]').click()
time.sleep(2)
driver.get('https://www.google.com/search?q=Flower%20shops&oq=flower+shops&aqs=chrome.0.69i59j69i57j0i271l3j69i60j69i61j69i60.1987j0j7&sourceid=chrome&ie=UTF-8&dlnr=1&sei=DW5lYsD7DNWEur4Pr8CT2A0&tbs=lf:1,lf_ui:10&tbm=lcl&sxsrf=APq-WBtzTXMsCEG8-8jHuqbpamowkj3Nlg:1650814482370&rflfq=1&num=10&rldimm=7685376553708120908&lqi=CgxGbG93ZXIgc2hvcHNIw4-b4dKtgIAIWhQQABABGAAiDGZsb3dlciBzaG9wc5IBD2Zsb3dlcl9kZXNpZ25lcpoBI0NoWkRTVWhOTUc5blMwVkpRMEZuU1VOdFgzVlFRMEpCRUFFqgEUEAEqECIMZmxvd2VyIHNob3BzKAA&phdesc=XQ9OeXHGpEI&ved=2ahUKEwiEv76Wg633AhVRLBoKHYiGAfIQvS56BAgMEAE&sa=X&rlst=f#dlnr=1&rlfi=hd:;si:7685376553708120908,l,CgxGbG93ZXIgc2hvcHNIw4-b4dKtgIAIWhQQABABGAAiDGZsb3dlciBzaG9wc5IBD2Zsb3dlcl9kZXNpZ25lcpoBI0NoWkRTVWhOTUc5blMwVkpRMEZuU1VOdFgzVlFRMEpCRUFFqgEUEAEqECIMZmxvd2VyIHNob3BzKAA,y,XQ9OeXHGpEI;mv:[[33.688926099999996,73.1433227],[33.5448866,72.9740797]];tbs:lrf:!1m4!1u3!2m2!3m1!1e1!1m4!1u2!2m2!2m1!1e1!2m1!1e2!2m1!1e3!3sIAE,lf:1,lf_ui:10')
time.sleep(10)
print('clicking ')
driver.find_element_by_xpath('//*[@class="DvzRrc ab_button"]').click()
print('Done')
time.sleep(5)
driver.find_element_by_xpath('//span[@class="VfPpkd-Jh9lGc"]').click()
time.sleep(15)
driver.find_element_by_xpath('//div[@aria-label="Five stars"]').click()
time.sleep(3)
driver.find_element_by_xpath('//*[@class="gLFyf gsfi"]').send_keys('cars')
time.sleep(2)
driver.find_element_by_xpath('//*[@class="gLFyf gsfi"]').send_keys(Keys.ENTER)
time.sleep(50)
def main():
login_Undetected()
if __name__ == "__main__":
main()
The Problem i am facing is after line 24
Solution 1:[1]
The elements i was trying to access was inside another i frame so i have to switch between them to interact with them i used
driver.switch_to.frame(driver.find_element_by_name("IFRAME NAME"))
#ENTER CODE HERE
#AFTER THAT SWITCH BACK TO DEFAULT WINDOW BY
driver.switch_to.default_content()
to switch between frames and that did the trick
please remember to switch back after your work is done
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Ahtesham Khan |

