Selenium 4 with python

62 views
Skip to first unread message

Bhavana Rakesh

unread,
Jul 19, 2024, 7:05:33 AMJul 19
to Selenium Users
Hello all,

Expected: I want to navigate to "https://bitcoin.org/en/buy"

1. Then Click on "AUD" currency selector dropdown.
2. In search bar, to enter "Ind"
3. Then select "Indonesian Rupiah" in the expanded dropdown.
4. Lastly, click on continue button.

Below is my code in pycharm IDE:

from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.support import expected_conditions as EC
import time

service_object = Service(r"C:\Users\Admin\Downloads\chromedriver-win64\chromedriver-win64\chromedriver.exe")

driver = webdriver.Chrome(service=service_object)

driver.get("https://bitcoin.org/en/")
time.sleep(5)

element_click = [(By.XPATH, '//*[@id="menusimple"]/li[4]/ul/li[2]/a'),
(By.XPATH, '//*[@id="widget-modal-root"]/div[2]/div[1]/div[1]/div/div/div/div[2]/button')]

for by_method, value in element_click:
try:
#Selecting participate menu and buy bitcoin submenu
element_buy_Bitcoin = WebDriverWait(driver, 100).until(EC.presence_of_element_located((by_method, value)))
driver.execute_script("arguments[0].click();", element_buy_Bitcoin)
time.sleep(10)
print(f"Clicked on participate and buy bit coin")
time.sleep(10)

#Clicking on currency dropdown
WebDriverWait(driver, 100).until(EC.presence_of_element_located(
(By.XPATH, '//*[@id="widget-modal-root"]/div[2]/div[1]/div[1]/div/div/div/div[2]/button/p'))).click()

time.sleep(20)

#Entering search critera in currency search field
enter_ind = WebDriverWait(driver, 60).until(EC.presence_of_element_located(
(By.XPATH, '//*[@id="widget-modal-root"]/div[2]/div[1]/div[1]/div[1]/div[2]/div/input')))
driver.execute_script("arguments[0].value='Ind';", enter_ind)
time.sleep(10)
#Slecting Indonesian Rupiah
WebDriverWait(driver, 20).until(EC.element_to_be_clickable((
By.CLASS_NAME, "flex w-full ml-2 text-left"
))).click()

time.sleep(10)


except Exception as e:
print("Not clickable")

driver.quit()


The output is 

Clicked on participate and buy bit coin
Clicked on {element_buy_Bitcoin}
Not clickable

Process finished with exit code 0

Himanshu Sheth

unread,
Aug 5, 2024, 8:35:43 AMAug 5
to Selenium Users
I tried this code out, the issue is that you need to first Move to "Participate" Menu. Post that, you need to locate the 'Buy Bitcoin' menu item and click on it (via ActionChains). This explains why you were getting ElementNotClickableException.

I was preparing repo for Selenium Python (beginner + intermediate), added a working example of your usecase in the repo. You can find it here.
Hope this helps. Happy to help & learn together.
________________________________________________________
Regards,
- Himanshu Jagdish Sheth
Director - Technical Content Marketing | Lead - Developer Evangelism
Reply all
Reply to author
Forward
0 new messages