0

Help me. I made a program, one of the actions is to click on the check out button on the site gamdom.com . The fact is that I have it working and everything is clicked. But the friend to whom I threw this program, this button does not profit. Whatever I do. Selenium does not give an error when you click on the button,but it does not click it.

in this code, the button is pressed by me, but not by a friend (it is pressed, but does not do anything, it will do after login to the site)

import time
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.by import By

def test(): #####################/CHECKOUT WILL DO SOMETHING ONLY AFTER LOGIN ON SITE/#####################################################
    driver = webdriver.Chrome(executable_path=r'C:/webdriver/79.0.3945.36/chromedriver.exe')
    driver.get("https://gamdom.io/marketplace/P2P") # open site
    try:
        driver.find_element_by_xpath("//div[@class='p2p-modal-content__ack']/input").click() # click checkbox
        driver.find_element_by_xpath("//div[@class='p2p-modal-content__button']/button").click() # click confirm
    except:
        pass
    driver.find_element_by_xpath("//div[@class='viewport normal-design']/div[3]/div[2]/div[2]/div[2]/div/div/div/div/div/div/div/div[1]").click() # click on first item
    print(1)
    driver.find_element_by_xpath(f"//div[@class='viewport normal-design']/div[3]/div[2]/div[2]/div[2]/div[2]/div[1]/div[2]/a").click() # click checkout
    print(2)
    input()
test()
AMC
  • 2,642
  • 7
  • 13
  • 35
MWorld
  • 1
  • 1
  • Maybe you don't see any error because `Except: pass`? Try to remove that first. Also it would be useful to know where exactly your script stuck. – Trapli Mar 30 '20 at 08:48
  • this action closes the pop-up window when you go to the site. this does not affect the click on the button – MWorld Mar 30 '20 at 11:39
  • We're going to need mroe information than this. What are the differences between your environment and the one where your friend is running the program? As an aside, you probably shouldn't use a bare `except` like that, see https://stackoverflow.com/questions/54948548/what-is-wrong-with-using-a-bare-except. – AMC Apr 11 '20 at 01:06

1 Answers1

0

I checked the page you linked. Well, your Xpaths can be improved a lot. A big chain of div/div/div... is not error-prone. Anything changes in the layout, your path stops working. To select elements properly, use attributes of elements to properly identify what are you looking for. For example:

driver.find_element_by_xpath('//*[@class="invItemContainer  interactive"]')

This will select the first box. If you want to find all boxes, you can:

driver.find_elements_by_xpath('//*[@class="invItemContainer  interactive"]')

Same applies to the 'checkout' url like above, it is not error-prone:

f"//div[@class='viewport normal-design']/div[3]/div[2]/div[2]/div[2]/div[2]/div[1]/div[2]/a"

What you should do instead:

driver.find_element_by_xpath('//div[@class="checkout_block bbb"]//a[@class="btn btn_green"]')

So basically try this:

driver.find_element_by_xpath('//*[@class="invItemContainer  interactive"]').click()
driver.find_element_by_xpath('//div[@class="checkout_block bbb"]//a[@class="btn btn_green"]').click()
Trapli
  • 1,517
  • 2
  • 13
  • 19