我在使用 selenium 在 c# 中单击时遇到问题打开下拉 select 选项
I facing problem open dropdown select option on click in c# using selenium
我正在尝试从我的帐户打开注册页面。
UI 开发人员使用了 bootstrap 代码。 Bootstrap开发者添加了JS点击功能。
当我 运行 这段代码显示错误“OpenQA.Selenium.ElementClickInterceptedException has been thrown
元素点击被截获:元素 ... 在点 (984, 50) 不可点击。其他元素将收到点击:...
(会话信息:chrome=77.0.3865.120)“
附上截图link:
https://monosnap.com/file/1z5PYCFBHfcXtkWJWVMi4SeejUXXOf
https://monosnap.com/file/hdq3194312RCnvc6GdQXLLVqtoezNJ
这是我的代码
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using OpenQA.Selenium;
using OpenQA.Selenium.Chrome;
using OpenQA.Selenium.Support.UI;
namespace XTSeleniumtest
{
class MainClass
{
public static void Main(string[] args)
{
IWebDriver driver = new ChromeDriver();
driver.Navigate().GoToUrl("http://freshpicksdev.isrv.tech/");
driver.FindElement(By.CssSelector("div.modal-header .close")).Click();
driver.FindElement(By.XPath("//a[@id='navbarDropdown']/u")).Click();
}
}
}
**`
> strong text
`**
您可以等到元素可见。
driver.FindElement(By.XPath("//a[@id='navbarDropdown']/u"));
如果问题仍然存在,请post DOM 网页结构,这可能与错误的元素交互有关。
试试下面的代码。您需要从 nuget
添加对 "SeleniumExtras.WaitHelpers" 的引用
class MainClass
{
public static void Main(string[] args)
{
IWebDriver driver = new ChromeDriver();
driver.Navigate().GoToUrl("http://freshpicksdev.isrv.tech/");
driver.FindElement(By.CssSelector("div.modal-header .close")).Click();
WebDriverWait wait = new WebDriverWait(driver, TimeSpan.FromSeconds(10));
wait.IgnoreExceptionTypes(typeof(NoSuchElementException));
wait.Until(SeleniumExtras.WaitHelpers.ExpectedConditions.ElementToBeClickable(By.XPath("//u[contains(text(),'My Account')]")));
driver.FindElement(By.XPath("//u[contains(text(),'My Account')]")).Click();
driver.FindElement(By.XPath("//a[text()='Register']")).Click();
}
}
我正在尝试从我的帐户打开注册页面。 UI 开发人员使用了 bootstrap 代码。 Bootstrap开发者添加了JS点击功能。 当我 运行 这段代码显示错误“OpenQA.Selenium.ElementClickInterceptedException has been thrown
元素点击被截获:元素 ... 在点 (984, 50) 不可点击。其他元素将收到点击:... (会话信息:chrome=77.0.3865.120)“
附上截图link: https://monosnap.com/file/1z5PYCFBHfcXtkWJWVMi4SeejUXXOf https://monosnap.com/file/hdq3194312RCnvc6GdQXLLVqtoezNJ
这是我的代码
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using OpenQA.Selenium;
using OpenQA.Selenium.Chrome;
using OpenQA.Selenium.Support.UI;
namespace XTSeleniumtest
{
class MainClass
{
public static void Main(string[] args)
{
IWebDriver driver = new ChromeDriver();
driver.Navigate().GoToUrl("http://freshpicksdev.isrv.tech/");
driver.FindElement(By.CssSelector("div.modal-header .close")).Click();
driver.FindElement(By.XPath("//a[@id='navbarDropdown']/u")).Click();
}
}
}
**`
> strong text
`**
您可以等到元素可见。
driver.FindElement(By.XPath("//a[@id='navbarDropdown']/u"));
如果问题仍然存在,请post DOM 网页结构,这可能与错误的元素交互有关。
试试下面的代码。您需要从 nuget
添加对 "SeleniumExtras.WaitHelpers" 的引用 class MainClass
{
public static void Main(string[] args)
{
IWebDriver driver = new ChromeDriver();
driver.Navigate().GoToUrl("http://freshpicksdev.isrv.tech/");
driver.FindElement(By.CssSelector("div.modal-header .close")).Click();
WebDriverWait wait = new WebDriverWait(driver, TimeSpan.FromSeconds(10));
wait.IgnoreExceptionTypes(typeof(NoSuchElementException));
wait.Until(SeleniumExtras.WaitHelpers.ExpectedConditions.ElementToBeClickable(By.XPath("//u[contains(text(),'My Account')]")));
driver.FindElement(By.XPath("//u[contains(text(),'My Account')]")).Click();
driver.FindElement(By.XPath("//a[text()='Register']")).Click();
}
}