我正在嘗試使用帶有C#的Selenium Webdriver來實現(xiàn)自動測試。我的頁面的右下角有一個使用JavaScript制作的圖片按鈕。我的HTML代碼:<html><head> <meta charset="utf-8"> <title>Sanofi - Digital Value Chain</title> <base href="/"> <meta name="viewport" content="width=device-width, initial-scale=1"> <meta name="description" content=""> <meta name="author" content=""> <link rel="icon" type="image/x-icon" href="assets/favicon-sanofi.png"><link href="styles.e3154dfb8e8b22c30979.bundle.css" rel="stylesheet"/></head><body> <app-root>Automatic testing page - Chatbot with Selenium + C# </app-root> <!-- Avaamo Chatbot --> <script type="text/javascript"> var AvaamoChatBot=function(t){function o(t,o){var n=document.createElement("script");n.setAttribute("src",t),n.onload=o,document.body.appendChild(n)}return this.options=t||{},this.load=function(t){o(this.options.url,function(){window.Avaamo.addFrame(),t&&"function"==typeof(t)&&t(window.Avaamo)})},this}; var chatBox = new AvaamoChatBot({url: 'https://c0.avaamo.com/web_channels/47afd7fd-6473-445a-bb87-4b4c46c51b94?locale=eng&bot_typing_duration=60000'}); chatBox.load(); </script><script type="text/javascript" src="inline.c239ca988071a28dfcf5.bundle.js"></script><script type="text/javascript" src="polyfills.1c766e36408e34083505.bundle.js"></script><script type="text/javascript" src="scripts.c7b8f195ebee14d64454.bundle.js"></script><script type="text/javascript" src="vendor.b1d0922e092ba105d6d7.bundle.js"></script><script type="text/javascript" src="main.44cb2cdc7217ee361473.bundle.js"></script></body></html>因此,我正在嘗試使用此C#代碼,但無法正常工作。//Create the reference for our browserIWebDriver driver = new ChromeDriver();//Navigate to LANDING PAGEdriver.Navigate().GoToUrl(BOT_ADDRESS_LOCAL_DISC);//Maximize window driver.Manage().Window.Maximize();有沒有人對此有解決方案???
2 回答

慕標琳琳
TA貢獻1830條經(jīng)驗 獲得超9個贊
要單擊圖像按鈕,您必須啟動WebDriverWait,并且可以使用以下代碼行:
IWait wait = new WebDriverWait(driver, TimeSpan.FromSeconds(3))
wait.Until(ExpectedConditions.ElementToBeClickable(By.XPath("//link[@rel='icon' and contains(@href,'favicon-sanofi.png')"))).Click();
- 2 回答
- 0 關注
- 173 瀏覽
添加回答
舉報
0/150
提交
取消