Farawa da Python Selenium Automation

Mataki 1: Shigar Selenium

Bude terminal ko command prompt kuma gudanar da umarni mai zuwa don shigar da Selenium ɗakin karatu ta hanyar pip:

pip3 install selenium

Mataki 2: Zazzagewa kuma Shigar WebDriver

Kama da hanyar da aka bayyana a cikin martanin da suka gabata, kuna buƙatar zazzagewa kuma shigar da wanda WebDriver ya dace da mai binciken da kuke son amfani da shi.

Mataki 3: Rubuta Python Code

A ƙasa akwai misalin yadda ake amfani da shi Selenium don buɗe shafin yanar gizon, yin bincike, da dawo da abun ciki:

from selenium import webdriver  
  
# Initialize the browser(using Chrome in this example)  
driver = webdriver.Chrome()  
  
# Open a web page  
driver.get("https://www.example.com")  
  
# Find an element on the web page  
search_box = driver.find_element_by_name("q")  
search_box.send_keys("Hello, Selenium!")  
search_box.submit()  
  
# Print the web page content after the search  
print(driver.page_source)  
  
# Close the browser  
driver.quit()  

Lura cewa misalin da ke sama yana amfani da burauzar Chrome. Idan kana son yin amfani da wani nau'in burauza, kana buƙatar maye gurbin webdriver.Chrome() da webdriver.Firefox() ko webdriver.Edge() bisa ga burauzar da kake son amfani da ita.

Muhimmiyar Bayani

  • Selenium yana buƙatar WebDriver sarrafa mai binciken gidan yanar gizo. Tabbatar kun shigar kuma saita madaidaiciyar hanya zuwa WebDriver.
  • Lokacin amfani Selenium da sarrafa mu'amalar mai binciken gidan yanar gizo, kula da yin hulɗa tare da matakan tsaro akan gidan yanar gizon kuma ku bi manufofin gidan yanar gizon.