链接在xpath Selenium Webdriver(Ajax容器)中不起作用

时间:2017-09-26 10:34:53

标签: python selenium selenium-webdriver

class ClickAndSendKeys():

    def test(self):
        # Driverlocation
        driverLocation = "C:/Users/Dennis.Pieruschka/Documents/chromedriver.exe"
        os.environ["webdriver.chrome.driver"] = driverLocation
        # Instantiate Chrome Browser Command
        driver = webdriver.Chrome(driverLocation)
        driver.maximize_window()
        url = "http://www.visservanbaars.nl/vacatures"
        driver.get(url)
        driver.find_element_by_xpath("//div[@id='ajax-container']//form//div//input").click()
        time.sleep(3)
        driver.find_element_by_xpath("//div[@id='ajax-container']//form//div//input").send_keys("Bi Consultant")
        time.sleep(3)
        driver.find_element_by_xpath("//div[@id='ajax-container']//form//div/span/button").click()

ff = ClickAndSendKeys()
ff.test()

当我运行此代码时,Selenium不会转到下一页

xpath是正确的但是当它点击它时会直接关闭窗口 有谁知道如何使用它?

1 个答案:

答案 0 :(得分:0)

我不知道python。请将其转换为JAVA

请检查此代码是否有效:

WebDriver driver=new FirefoxDriver();
driver.get("http://www.visservanbaars.nl/vacatures");
WebElement elem=    driver.findElement(By.xpath("//div[@id='ajax-container']//form//div//input"));
elem.sendKeys("World");
elem.sendKeys(Keys.ENTER);