簡體   English   中英

在 Robot Framework 中使用 Selenium.Webdriver 和 SeleniumLibrary

[英]Using Selenium.Webdriver and SeleniumLibrary in Robot Framework

我是 IT 和自動化 QA 方面的新手,在 RobotFramework 中使用 Selenium 庫和 SeleniumLibrary 時遇到了麻煩。 據我所知,SeleniumLibrary 將支持在機器人框架(RF)中使用方法作為關鍵字。 假設在 *.py 文件中我可以使用 Selenium 來調用打開的瀏覽器:

driver = webdriver.Chrome() driver.get("https://google.com")...

在 *.robot 我用 SeleniumLibrary 打開一個瀏覽器,比如:

open browser https://google.com

在研究許多解決方案時,我在 Selenium 中發現了許多教程,並且易於理解和應用,但在我的項目中,他們一直在擴展 SeleniumLibrary:

driver = SeleniumLibrary
driver.open_browser("https://google.com")

= driver.get("https://google.com") in *.py ( from selenium import webdriver )

我覺得很難閱讀 SeleniumLibrary 的源代碼,例如如果我需要在 *.py 和 SeleniumLibrary 中使用find_element(By.ID/CSS/etc.., "abc")我只搜索過

def find_element(
        self,
        locator: str,
        tag: Optional[str] = None,
        required: bool = True,
        parent: WebElement = None,
    )

我不會像以前那樣用 selenium.webdriver 編寫代碼。有沒有人幫我清除它們? 如何在 *.py 文件中使用driver.find_element (SeleniumLibrary)等於driver.find_element_by_CSS_selector (Selenium.webdriver)

如何在頁面上定位元素有多種策略,請在此處的文檔中閱讀它們。

關鍵是你想對你定位的元素做一些事情,在 Python 中,你通常分兩步完成,首先找到元素然后單擊它(例如)。 在 Robot Framework 中,您可以像這樣一步完成它:

Click Element    id:foo

就這樣。 這里有兩個步驟:

  • 在 DOM 中查找元素
  • 點擊元素

Robot Framework 比 Python 更高級一些,因此其中的許多任務將需要更少的代碼行。 我認為這是您要問的問題,但還沒有真正習慣。 我建議在一個小項目上使用 RF 來學習它。 您始終可以在 Internet 上准備好文檔。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM