Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/sql-server-2008/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Selenium webdriver c#-无法单击()元素(元素不为null)_C#_Ajax_Xpath_Selenium_Webdriver - Fatal编程技术网

Selenium webdriver c#-无法单击()元素(元素不为null)

Selenium webdriver c#-无法单击()元素(元素不为null),c#,ajax,xpath,selenium,webdriver,C#,Ajax,Xpath,Selenium,Webdriver,我似乎在单击由ajax填充的框中的元素时遇到问题 因此,我所在的网页上有一个链接,当点击这个链接时,会调用一个javascript函数,然后将一个新的div插入到充满新内容的页面中 现在奇怪的是,我可以在这个框中找到元素,使用xpath没有问题,我甚至可以读取它的值,但是!我不能使用Click();在盒子里的链接上,由于某种原因,活动无法进行 有没有人遇到过类似的问题,并且知道如何解决 我在Firefox23上使用SeleniumWebDriver 2.35 More Info 好的,我单击

我似乎在单击由ajax填充的框中的元素时遇到问题

因此,我所在的网页上有一个链接,当点击这个链接时,会调用一个javascript函数,然后将一个新的div插入到充满新内容的页面中

现在奇怪的是,我可以在这个框中找到元素,使用xpath没有问题,我甚至可以读取它的值,但是!我不能使用Click();在盒子里的链接上,由于某种原因,活动无法进行

有没有人遇到过类似的问题,并且知道如何解决

我在Firefox23上使用SeleniumWebDriver 2.35

 More Info
好的,我单击的链接的HTML调用JS以显示div

<center>
    <a id="link_fleet_move_here" href="">Move fleet here</a>
</center>
<br>
<script>
    $("#link_fleet_move_here").click( function(event) { event.preventDefault(); load_fleet_move_to_destination("fleet.aspx?method=ajax&view=move_to_destination&version=1&player=111&destination=LZLOCATION"); $("#link_fleet_move_here").hide();} )
</script>
<center>
<div id="fleetLoaderTemplate" style="display:none">
<div id="fleetLoaderErrorTemplate" style="display:none">
</center>
<div id="move_to_destination_container"></div>
我认为这可能与那个div有关,实际上,我认为它是从Display开始的:无,然后被更改,这会影响它吗


我以为它是动态添加的,但可能不是

尝试通过以下方式选择元素:

driver.findElement(By.cssSelector("#move_to_destination_container a[href^='fleet']")).click();
如果抛出错误,请尝试使用:

new WebDriverWait(driver, 10).until(ExpectedConditions.presenceOfElementLocated(By.cssSelector("#move_to_destination_container a[href^='fleet']"))).click();

我猜,
click()
执行一些javascript。尝试通过Actions API或javascript执行单击。有时候你不得不做这样的变通。我不是说Webdriver使用Javascript,而是页面的按钮上附加了一个Javascript事件。将驱动程序强制转换为JavascriptExecutor,然后尝试从那里执行单击。不,我单击一个激发一些JS的链接,JS向页面添加一个新div,然后我在这个新div中选择一个链接,我可以找到这个元素,甚至返回它的文本/值/属性,但click()不会单击它。该元素只是指向另一个未附加到任何JS的页面的链接。那么您可以发布一些HTML以及您正在使用的选择器吗?可能是您选择了错误的元素。好吧,老实说,我认为这与CSS有关。但我想只要我能看到它,我就能看到它:/我的意思是它发现它没问题。对不起,一直打扰你,但那会点击什么?因为生成的div在一个表中包含一个巨大的链接列表,而我所做的xpath选择器是找到我想要单击的正确链接的唯一方法。
driver.findElement(By.cssSelector("#move_to_destination_container a[href^='fleet']")).click();
new WebDriverWait(driver, 10).until(ExpectedConditions.presenceOfElementLocated(By.cssSelector("#move_to_destination_container a[href^='fleet']"))).click();