2

while learning how to use selenium, Im trying to click an element but nothing happens and Im unable to reach the next page. this is the relevant page: http://buyme.co.il and Im trying to click: הרשמה

I managed to print the desired element (הרשמה) so I guess Im reaching the correct place in the page. but 'click()' doesnt work. the second span <span>הרשמה</span> is what i want to click:

<li data-ember-action="636">
        <a>
            <span class="seperator-link">כניסה</span>
            <span>הרשמה</span>
        </a>
 </li>
for elem in driver.find_elements_by_xpath('//* [@id="ember591"]/div/ul[1]/li[3]/a/span[2]'):
    print (elem.text)
    elem.click()

also tried this:

driver.find_element_by_xpath('//*[@id="ember591"]/div/ul[1]/li[3]/a').click()

I expected to get to the "lightbox" which contain the registration fields. Any thoughts on the best way to accomplish this?

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
holder
  • 93
  • 1
  • 10

2 Answers2

2

Explicit Waits - An explicit wait is a code you define to wait for a certain condition to occur before proceeding further in the code.

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

browser = webdriver.Chrome()
browser.get("https://buyme.co.il/")

WebDriverWait(browser, 10).until(EC.element_to_be_clickable((By.ID, 'ember591')))

elm = browser.find_elements_by_xpath('//div[@id="ember591"]/div/ul[1]/li[3]/a')

elm[0].click()

enter image description here

Update:

WebDriverWait(browser, 10).until(EC.element_to_be_clickable((By.CLASS_NAME, 'login')))

email = browser.find_elements_by_xpath("//form[@id='ember1005']/div[1]/label/input")
email[0].send_keys("abc@gmail.com")

password = browser.find_elements_by_xpath("//form[@id='ember1005']/div[2]/label/input")
password[0].send_keys("test1234567")

login = browser.find_elements_by_xpath('//form[@id="ember1005"]/button')
login[0].click()

enter image description here

bharatk
  • 4,202
  • 5
  • 16
  • 30
  • 1
    it looks like that worked. however the browser closes imminently so I wasnt sure I reached the "lightbox". is there a way to keep it open? – holder Jun 09 '19 at 13:22
  • @holder Always use `WebDriverWait` wait utils object is not available or if you don't know HTML elements then use `time` module.`import time` – bharatk Jun 10 '19 at 06:35
  • `time.sleep(4)` – bharatk Jun 10 '19 at 06:38
0

The desired element is an Ember.js enabled element so to locate the element you have to induce WebDriverWait for the element to be clickable and you can use the following Locator Strategy:

  • Using XPATH:

    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//span[text()='הרשמה']"))).click()
    
  • Note : You have to add the following imports :

    from selenium.webdriver.support.ui import WebDriverWait
    from selenium.webdriver.common.by import By
    from selenium.webdriver.support import expected_conditions as EC
    
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
  • looks like your method works as well. thanks. im not familiar with Ember.js or javascript so thanks for the info. also, in your code you wrote: `expected_conditions as EC` is this necesary or can you use just `expected_conditions`? – holder Jun 09 '19 at 14:42
  • @holder As per my import `from selenium.webdriver.support import expected_conditions as EC` I have sweetened the long `expected_conditions` as **`EC`** for the ease of use. – undetected Selenium Jun 09 '19 at 15:03
  • nice! so moving further with this, Im trying to click other elements inside the "lightbox". not wanting to bother you people for every element, I need to understand the logic of this. I tried clicking on `להרשמה` using this: `driver.find_element_by_xpath('//*[@id="ember572"]/div/div[1]/div/div/div[3]/p/span[text()=להרשמה]').click()` whats wrong with this approach? – holder Jun 09 '19 at 15:37
  • @holder Let's not stretch this discussion as you are having an accepted answer. Good luck – undetected Selenium Jun 09 '19 at 16:41