How should I write the script to click a div or span element instead of a button or a tag?
When clicking elements such as <div> や <span>, there are two approaches depending on whether the target element contains display text.
1. When the <div> contains display text (Recommended)
You can directly use await Web.ClickButtonAsync(“Text”) or await Web.ClickLinkAsync(“Text”).
ChronoATX’s click APIs come with a built-in 3-stage automatic fallback mechanism:
A) Prioritizes searching for [<button> tags or elements with the role=”button” attribute
B) Searches for <a> tags
C) Final fallback: Automatically identifies and fires a click on any DOM element containing the specified text (<div>, <span>, <li>, etc.)
// 例: <div class="card-btn">ホーム</div> をクリックする場合
await Web.ClickButtonAsync("ホーム");
2. When the <div> does not contain text (Icons only, or specified via CSS selectors)
Combine and use Web.FindAsync() with ClickAsync().
// CSS セレクターで対象の div を取得してクリック
var myDiv = await Web.FindAsync("div.icon-close");
await myDiv.ClickAsync();
// 1 行で記述することも可能です
await (await Web.FindAsync("div.card-active")).ClickAsync();
Was this article helpful?
Thank you for helping us improve our documentation.