1

这是我试图访问的代码

<div class="field checkbox">
  <label class="radio">
    <input payoneer="CheckBox" type="checkbox" name="ctl00$plcMainArea$SignDocument_4_2" validate="validate" data-rule-required="true" data-msg-required="This field is required." hidefocus="hidefocus" class="field-data" id="SignDocument_4_2" data-sign-document-type="4_2">&nbsp;I agree to the
    <a href="pagecontent.payoneer?rsckey=ProcessorTypeDebitCard.ElectronicDisclosure&amp;pid=Y0LwV0AQC7cY%2b5AIqsZl1g%3d%3d" target="_blank">Electronic Disclosures</a>
    <a href="pagecontent.payoneer?rsckey=ProcessorTypeDebitCard.Privacy&amp;pid=Y0LwV0AQC7cY%2b5AIqsZl1g%3d%3d" target="_blank">Privacy Policy</a>
  </label>
</div>

我正在尝试按 ID 查找元素并单击其上的复选框

driver.FindElement(By.Id("SignDocument_4_2")).Click();

这是我得到的例外

System.InvalidOperationException was unhandled
  HResult=-2146233079
  Message=unknown error: Element is not clickable at point (257, 955). Other element would receive the click: <a href="pagecontent.payoneer?rsckey=ProcessorTypeDebitCard.ElectronicDisclosure&amp;pid=Y0LwV0AQC7cY%2b5AIqsZl1g%3d%3d" target="_blank">...</a>
  (Session info: chrome=48.0.2564.116)
  (Driver info: chromedriver=2.20.353145 (343b531d31eeb933ec778dbcf7081628a1396067),platform=Windows NT 6.1 SP1 x86_64)
  Source=WebDriver
  StackTrace:
       at OpenQA.Selenium.Remote.RemoteWebDriver.UnpackAndThrowOnError(Response errorResponse)
       at OpenQA.Selenium.Remote.RemoteWebDriver.Execute(String driverCommandToExecute, Dictionary`2 parameters)
       at OpenQA.Selenium.Remote.RemoteWebDriver.InternalExecute(String driverCommandToExecute, Dictionary`2 parameters)
       at OpenQA.Selenium.Remote.RemoteWebElement.Execute(String commandToExecute, Dictionary`2 parameters)
       at OpenQA.Selenium.Remote.RemoteWebElement.Click()
       at Payoneer.Exam.Main(String[] args) in c:\Users\Alberto Chocron\Documents\Visual Studio 2013\Projects\PayoneerTest\Payoneer\Program.cs:line 105
       at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
       at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
       at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
       at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
       at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
       at System.Threading.ThreadHelper.ThreadStart()
  InnerException: 
4

2 回答 2

1

该错误Element is not clickable at point (257, 955). Other element would receive the click意味着您要单击的元素对于 Selenium 不可见。模拟MoveToElementActions类使用元素的移动

IWebElement checkbox = driver.FindElement(By.Id("SignDocument_4_2"));
Actions actions = new Actions(driver);
actions.MoveToElement(checkbox).perform();
checkbox.Click();

您也可以尝试将点击发送到复选框父母

driver.FindElement(By.ClassName("checkbox")).Click();
// or
driver.FindElement(By.ClassName("radio")).Click();

另一种选择是使用java脚本点击

IWebElement checkbox = driver.FindElement(By.Id("SignDocument_4_2"));
IJavascriptExecutor executor = (IJavascriptExecutor)driver;
executor.ExecuteScript("arguments[0].click();", checkbox);
于 2016-03-03T16:20:39.397 回答
0

首先,请查看您是否使用了正确的 try 和 catch 块,或者该方法被正确抛出,其次,实际上没有检测到该点。所以试试

            string checkboxXPath = "//input[contains(@id, SignDocument_4_2')]"
            IWebElement elementToClick = driver.FindElement(By.XPath(checkboxXPath));
            elementToClick.Click();
于 2016-03-04T05:45:10.920 回答