简体   繁体   中英

Why does it take so much to search for an xpath where i insert the value of contains(text(), variable)?

for i in range(len(tlds)):
    #print("TLD at index " + str(i) + " is " + tlds[i])
    try:
        print("Cerca sito...")
        sito = WebDriverWait(driver, 0.2).until(EC.presence_of_element_located((By.XPATH, "//div[contains(text(),'" + str(tlds[i]) +"') and @class ='Io6YTe fontBodyMedium']"))).text
    except:
        #print("T1")
        sito = None
    if sito is not None:
        print("T2")
        break

Here is the code: the part that is taking me so long is sito=... it cycles correctly through the loop but takes so much

I printed the result of site and actually it's correct: prints the tlds[i] between quotation marks but just takes so long.

In an an end-to-end test there were a lot of variables at play, a couple of examples can be Sauce startup , Browser start up and latency to and from the application under test, which may not be visible through the naked eye. Hence the delay.

You can find a couple of relevant detailed discussions in:

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