Goal:
Stages:
Problem:
I've checked inspect to make sure
Code:
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.by import By
from selenium.webdriver.support.wait import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from time import sleep
chrome_options = webdriver.ChromeOptions()
driver = webdriver.Chrome(executable_path=r'C:\Users\user\OneDrive\Desktop\selenium\chromedriver.exe', options=chrome_options)
# go to login page
driver.get("https://accounts.google.com/login?hl=id")
# write the email address
email = driver.find_element("name", "identifier")
email.send_keys("email@gmail.com")
sleep(2)
email.send_keys(Keys.RETURN)
sleep(5)
# write the password
password = driver.find_element("name", "Passwd")
password.send_keys("Password")
password.send_keys(Keys.RETURN)
sleep(5)
# go to review page
driver.get("https://search.google.com/local/writereview?placeid=ChIJDf8ln6V5ei4REzngJl6HEEc&pli=1")
sleep(8)
driver.find_element("aria-label", "Lima bintang").click()
How to solve this problem? At least to click the 5 stars. Thanks
That elements block is inside an iframe. So, you need to switch into the iframe to access those elements. So, you code can be as following:
driver.get("https://search.google.com/local/writereview?placeid=ChIJDf8ln6V5ei4REzngJl6HEEc&pli=1")
WebDriverWait(driver, 20).until(EC.frame_to_be_available_and_switch_to_it(driver.find_element(By.XPATH, "//div[not(@aria-hidden)]/iframe[@name='goog-reviews-write-widget']")))
driver.find_element("aria-label", "Lima bintang").click()
When finished working inside that iframe do not forget to get out to the default content with
driver.switch_to.default_content()
if you want to continue your test flow.
Also, instead of all these hardcoded pauses you should use WebDriverWait
expected_conditions
explicit waits.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.