簡體   English   中英

使用C#的Selenium WebDriver - 如何找到這些按鈕?

[英]Selenium WebDriver with C# - How can I locate these buttons?

我試圖點擊這些按鈕,但我沒有得到任何東西。 即使xpath也無法接收它們。 有沒有人知道如何找到這些按鈕?

<button class="rt-button rt-dialog-button" title="" value="">Close</button>
<button class="rt-button rt-dialog-button" title="" value="">OK</button>

非常感謝任何幫助

編輯:

感謝您的幫助。 這些建議都沒有對我有用,但我確實使用了以下方法:

C#

IWebElement OKButton = driver.FindElement(By.XPath(("//button[@class='rt-button rt-dialog-button'][2]")));

IWebElement CloseButton = driver.FindElement(By.XPath(("//button[@class='rt-button rt-dialog-button'][1]")));

我用xpath找到它們:

By.XPath("//button[text()='Close']")
By.XPath("//button[text()='OK']")

您可以為每個元素添加ID。

<button id="closeButton" class="rt-button rt-dialog-button" title="" value="">Close</button>
<button id="okButton" class="rt-button rt-dialog-button" title="" value="">OK</button>

然后找到它你可以做類似的事情

IWebElement element = driver.FindElement(By.Id("closeButton"));
IWebElement element = driver.FindElement(By.Id("openButton"));

我有時間在課堂上捕捉困難,x-path和ID有幫助。

我想你可以嘗試這個xpath:

//button[contains(text(),'Close')]

//[.='OK']

如果這不起作用,那么您有多個隱藏相同文本或頁面某處的元素

暫無
暫無

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

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