简体   繁体   中英

Wait for page load / element visible in Selenium using FirefoxDriver

I wonder what the best option is for wait of page load / elemnt visible in Selenium when I am using FirefoxDriver. I do not want to use the dom tree.

I know that I can use some king of Thread.sleep(number) but I do not like to set a fixed number since I would like to continue as fast as possible.

I found for example: Point position = driver.findElement(By.xpath(xpath)).getLocation();

I have also tried:

WebDriverWait wait = new WebDriverWait(driver, 20);
wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath(xpath)));

But I only get expected condition failed even thou I know this xpath exists.

Is it possible to use this one with an additional of While it is NULL or not is possible to find? My problem is that I can´t find / understand if the thing I try effects the DOM so the "page owner" can see that it is not a human searching the page.

My code looks something like this:

FirefoxDriver driver = Webdriver.getDriver();
        
String BASE_URL = "https://www.webpage.com/";
driver.get(BASE_URL);

In getDriver() I set properties and also "fp.setPreference("dom.webdriver.enabled", false);"

I have been using this and this one is working fine for me

try:
        WebDriverWait(context.driver, timeout).until(
            expected_conditions.presence_of_element_located((By.CSS_SELECTOR, '#element')))
    except():
        print("Element didn't load yet...")

You can try this hope this one will work perfect...😊

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM