Quantcast
Channel: Active questions tagged selenium - Stack Overflow
Viewing all articles
Browse latest Browse all 98221

Looping through a series of web elements of common class name

$
0
0

I'am writing a code to do the following using python and selenium:

1.go to google maps and search London Restaurants

2.click on first restaurant to view details and then go back to previous page and click the next restaurant (i, i+1, i+2 etc...)

  1. Note all restaurant click pages have common class names (being 'section-result')

however when I'am running the code, for some reason, driver is not clicking on the restaurant to go to the details page.

I have tried the following code, which also was suggested in another forum post for this problem. However so far unsuccessfully.

also i have tried to do a for loop which i have also included in the code section as (option 2)

from selenium import webdriver
import random
import time
import pandas as pd
driver=webdriver.Chrome(executable_path="C:/users/usr/Desktop/chromedriver.exe")


UrlA = "https://www.google.com/maps/search/"
UrlB= "London"
UrlC="Restaurant"
UrlD= UrlA + UrlB + '+' + UrlC
driver.get("http://www.google.com/ncr") #to load page in english language
driver.get(UrlD)



time.sleep(2)
driver.maximize_window()

elements = driver.find_elements_by_class_name('section-result')

Option 1:

for i in elements:
    i.click()
    driver.back()

Option 2:

for i in range (1,20):
    elements[i].click
    driver.back

the code line (i dot click) is not responding and instead its going back to previous page. Please advise the correct modification for the code


Viewing all articles
Browse latest Browse all 98221

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>