Python でミリ秒単位で Selenium WebDriver をスリープする
質問:
どうすれば一時停止できますか?を使用して Selenium WebDriver をミリ秒間実行しますPython?
答え:
time.sleep(secs) を使用する
時間ライブラリを使用して WebDriver をスリープできます浮動小数点数を渡すことでミリ秒間秒:
import time time.sleep(0.25) # Sleeps for 250 milliseconds
注意:
ただし、特定の条件なしで time.sleep(secs) を使用すると、要素の状態をチェックせずに実行が一時停止されるため、自動化の目的が無効になります。 .
推奨されるアプローチ:
代わりにtime.sleep(secs) の場合は、WebDriverWait を Expected_conditions と組み合わせて使用して、続行する前に要素の状態を検証します。一般的に使用される 3 つの Expect_conditions を次に示します。
presence_of_element_located(locator)
要素が DOM 上に存在することを検証します。 Visibility.
visibility_of_element_located(locator)
要素が存在し、表示され、高さがゼロでないことを確認し、 width.
element_to_be_clickable(locator)
要素が表示され、有効化され、 clickable.
例:
from selenium.webdriver import WebDriverWait from selenium.webdriver.common.by import By from selenium.webdriver.support import expected_conditions as EC # Wait 10 seconds until the element with the ID "my_element" becomes visible before clicking it WebDriverWait(driver, 10).until(EC.visibility_of_element_located((By.ID, "my_element"))) driver.find_element(By.ID, "my_element").click()
参考:
- [WebDriverWait が期待どおりに動作しない]( )
以上がPython の Selenium WebDriver をミリ秒間スリープさせるにはどうすればよいですか?の詳細内容です。詳細については、PHP 中国語 Web サイトの他の関連記事を参照してください。

Pythonは解釈された言語ですが、コンパイルプロセスも含まれています。 1)Pythonコードは最初にBytecodeにコンパイルされます。 2)ByteCodeは、Python Virtual Machineによって解釈および実行されます。 3)このハイブリッドメカニズムにより、Pythonは柔軟で効率的になりますが、完全にコンパイルされた言語ほど高速ではありません。

useaforloopwhenteratingoverasequenceor foraspificnumberoftimes; useawhileloopwhentinuninguntinuntilaConditionismet.forloopsareidealforknownownownownownownoptinuptinuptinuptinuptinutionsituations whileoopsuitsituations withinterminedationations。

pythonloopscanleadtoErrorslikeinfiniteloops、ModifiningListsDuringiteration、Off-Oneerrors、Zero-dexingissues、およびNestededLoopinefficiencies.toavoidhese:1)use'i

forloopsareadvastountousforknowterations and sequences、offeringsimplicityandeadability;

pythonusesahybridmodelofcompilation andtertation:1)thepythoninterpretercompilessourcodeodeplatform-indopent bytecode.2)thepythonvirtualmachine(pvm)thenexecuteTesthisbytecode、balancingeaseoputhswithporformance。

pythonisbothintersedand compiled.1)it'scompiledtobytecode forportabalityacrossplatforms.2)bytecodeisthenは解釈され、開発を許可します。

loopsareideal whenyouwhenyouknumberofiterationsinadvance、foreleloopsarebetterforsituationsは、loopsaremoreedilaConditionismetを使用します

henthenumber ofiterationsisknown advanceの場合、dopendonacondition.1)forloopsareideal foriterating over for -for -for -saredaverseversives likelistorarrays.2)whileopsaresupasiable forsaresutable forscenarioswheretheloopcontinupcontinuspificcond


ホットAIツール

Undresser.AI Undress
リアルなヌード写真を作成する AI 搭載アプリ

AI Clothes Remover
写真から衣服を削除するオンライン AI ツール。

Undress AI Tool
脱衣画像を無料で

Clothoff.io
AI衣類リムーバー

Video Face Swap
完全無料の AI 顔交換ツールを使用して、あらゆるビデオの顔を簡単に交換できます。

人気の記事

ホットツール

SublimeText3 Mac版
神レベルのコード編集ソフト(SublimeText3)

VSCode Windows 64 ビットのダウンロード
Microsoft によって発売された無料で強力な IDE エディター

WebStorm Mac版
便利なJavaScript開発ツール

PhpStorm Mac バージョン
最新(2018.2.1)のプロフェッショナル向けPHP統合開発ツール

EditPlus 中国語クラック版
サイズが小さく、構文の強調表示、コード プロンプト機能はサポートされていません
