簡體   English   中英

Selenium和Javascript,無法找到firstchild元素

[英]Selenium and Javascript, unable to locate firstchild element

我是Java語言和Selenium的新手,所以請多多包涵!

我如何找到“接受”元素並單擊它?

在此處輸入圖片說明

我嘗試了幾種組合:

var buttons =[];
buttons = driver.findElement(By.className("eula-button")) (I cannot call buttons.length with this method to loop through elements)

driver.findElement(By.xpath(".//button[contains(text(),'Accept')]")).click();

謝謝你的幫助!

嘗試使用xpath之類的東西-

var button = driver.findElement(By.xpath("//button[@class='eula-button']"));

您使用的xpath選擇器可以正常工作。

driver.findElement(By.xpath(".//button[contains(text(),'Accept')]")).click();

另外,您可以在CSS中使用索引,假設“接受”按鈕將始終出現在“拒絕”之前。

driver.findElement(By.cssSelector(".eula-button-container button.eula-button:nth-of-type(1)")

考慮到您使用XPath的第一個選擇器不起作用,我猜這些按鈕在iframe中,正如@Grasshopper的評論中指出的那樣。

在與按鈕交互之前,您將必須切換到框架,然后執行findElement

暫無
暫無

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

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