我想使用 selenium 在網頁中的 iFrame 中找到控制元件,以執行單擊和在文本框中設定文本等操作。使用 c# 或 java 語言的最佳方法是什么。
uj5u.com熱心網友回復:
通過使用下面的代碼,您可以在 chrome 驅動程式中的 iframe 中獲得控制元件。安裝最新的 selenium chromedriver 并將其放在 C:\chromedriver.exe 到下面的代碼
System.setProperty("webdriver.chrome.driver", "C:\\chromedriver.exe");
// Initialize browser
WebDriver driver=new ChromeDriver();
//navigate to url
driver.get("https://demoqa.com/frames");
//Switch to Frame using Index
driver.switchTo().frame(0);
//Identifying the heading in webelement
WebElement frame1Heading= driver.findElement(By.id("sampleHeading"));
//Finding the text of the heading
String frame1Text=frame1Heading.getText();
//Print the heading text
System.out.println(frame1Text);
//closing the driver
driver.close();
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/459098.html
標籤:硒
下一篇:帶硒的select2下拉選單
