0

i am trying to print the prices from inside the carousel at the top of gog.com.

my script works for some of the prices but not many. i dont understand, theyre basically all the same. i copy and pasted the xpaths, and theyre all basically the same except for their first a tag.

22.99 is at 
/html/body/div[2]/div/div[3]/div/div[3]/div[2]/div/a[8]/div[2]/div/div/div[3]/div/span[2]/span

5.69 is at 
/html/body/div[2]/div/div[3]/div/div[3]/div[2]/div/a[7]/div[2]/div/div/div[3]/div/span[2]/span

the output i receive is shown below, (the number is printed inbetween the objects. note the empty spaces where there are no numbers)

<selenium.webdriver.remote.webelement.WebElement (session="097dd18658222032f950b705069bfafb", element="3aed9a9c-b010-41e0-a35d-0a2a0d2e98da")>
22.59
<selenium.webdriver.remote.webelement.WebElement (session="097dd18658222032f950b705069bfafb", element="f9dc7bcf-9e1b-482e-9bf7-fd433326f2f3")>

<selenium.webdriver.remote.webelement.WebElement (session="097dd18658222032f950b705069bfafb", element="bd7114ab-8012-4f57-b84d-49e172363cd9")>

my script is below

from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By
from selenium import webdriver

driver = webdriver.Chrome(executable_path=r"../Downloads/chromedriver.exe")
driver.get('https://www.gog.com/')
driver.maximize_window()
WebDriverWait(driver,10).until(EC.presence_of_element_located((By.XPATH,"/html/body/div[2]/div/div[3]/div/div[3]/div[2]/div/a[10]/div[2]/div/div/div[3]/div/span/span")))

A = "/html/body/div[2]/div/div[3]/div/div[3]/div[2]/div/a[4]/div[2]/div/div/div[3]/div/span[2]/span" # this works       it print 22.59
print(driver.find_element_by_xpath(A));
print(driver.find_element_by_xpath(A).text);
A = "/html/body/div[2]/div/div[3]/div/div[3]/div[2]/div/a[7]/div[2]/div/div/div[3]/div/span[2]/span" # this doesnt work, it should print 5.69
print(driver.find_element_by_xpath(A));
print(driver.find_element_by_xpath(A).text);
A = "/html/body/div[2]/div/div[3]/div/div[3]/div[2]/div/a[8]/div[2]/div/div/div[3]/div/span[2]/span" # this doesnt work, it should print 22.99
print(driver.find_element_by_xpath(A));
print(driver.find_element_by_xpath(A).text);
  • Are you sure there are more than 6 links displaying in the html? you can use the devtools to validate the same using `/html/body/div[2]/div/div[3]/div/div[3]/div[2]/div` in the dev tools as shown [here](https://stackoverflow.com/questions/55870609/is-there-a-way-to-learn-xpath-without-using-firebug-or-xpath-as-firefox-is-not-s/55870909#55870909) – supputuri Apr 02 '20 at 13:26
  • yes, infact i copy and pasted each xpath in the same way, i didnt type anything for the xpath. – micurrent666 Apr 02 '20 at 14:02
  • i did as you recommended. the console seems to find the element eg it returns "[span.big-spot__price-amount]" – micurrent666 Apr 02 '20 at 14:21
  • Ok, cool. Now try `/html/body/div[2]/div/div[3]/div/div[3]/div[2]/div/a` and get the `size()` – supputuri Apr 02 '20 at 14:29
  • $x("/html/body/div[2]/div/div[3]/div/div[3]/div[2]/div/a").length returns 13 – micurrent666 Apr 02 '20 at 14:31
  • How about `$x("(/html/body/div[2]/div/div[3]/div/div[3]/div[2]/div/a)[7]/div[2]/div/div/div[3]/div/span[2]")` – supputuri Apr 02 '20 at 14:41
  • If that does not work start removing the element from back and see where it's going off. – supputuri Apr 02 '20 at 14:43

0 Answers0