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?

3
  • You can use the pyautogui module. You can find documentation here Commented Jun 8, 2019 at 15:03
  • 1
    @ArnavPoddar that is an interesting idea, however im specifically trying to accomplish this task using selenium. Commented Jun 8, 2019 at 15:08
  • Ok, good luck on your program Commented Jun 9, 2019 at 16:28

2 Answers 2

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("[email protected]")

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

Sign up to request clarification or add additional context in comments.

3 Comments

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 Always use WebDriverWait wait utils object is not available or if you don't know HTML elements then use time module.import time
time.sleep(4)
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
    

4 Comments

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 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.
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 Let's not stretch this discussion as you are having an accepted answer. Good luck 👍

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.