有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java如何在SeleniumWebDriver中单击FindNow按钮?

    <div id="queryButton_ns_033T372D9A50ZCTW273X_1889_" 
style="display:inline-block text-align:center;">

    <input type="image" 
alt="Find Now" src="http://g-ecx.images-amazon.com/images/G/31/rcx-gs/abn/button-find-now._V369364970_.png">

如何点击链接??它既不能使用id也不能使用xpath


共 (1) 个答案

  1. # 1 楼答案

    因此,点击这个按钮的方式目前有两个选项,你已经要求

    看起来您不能使用id,因为每次加载页面时它都会更改。 但是,如果您可以捕获动态生成的id,它会这样做:

    WebElement we5 = null;
    we5 = driver.findElement(By.id("queryButton_ns_0S7SWJ42MS972TW2Z74G_1576_"));
    we5.cl‌​ick();
    

    或者

    至于xpath,它应该非常简单:

    WebElemet we5 = null;
    we5 = driver.findElement(By.xpath("/html/body/div[4]/div/div[4]/div/div/div/table/tbody/tr/td[2]/form/div[2]/input"));
    we5.click();