如何 select 'Start' 按钮并使用 find_element_by_xpath 或 selenium-python API 从以下 HTML 代码中单击它
How to select 'Start' button and click it from following HTML code by using find_element_by_xpath or selenium-python API
如何 select 'Start' 按钮并通过以下 HTML 代码单击它。
我想使用以下 python-selenium
库
喜欢:
driver.find_element_by_xpath('//div[contains(@class,"box enter")'
'and text() = "start"]').click()
HTML代码
<section class="LandingPageView shown" style="display: block;">
<div class="background"></div>
<div class="gradient"></div>
<div class="page" style="opacity: 1;">
<div class="background asset background-homepage"></div>
<div class="just-reflektor-link" style="width: 312.289575px; height: 381.447127941177px; right: 25.635%;"></div>
<div class="content" style="right: -14.3125px; margin-left: 0px; transform: scale(1); -webkit-transform: scale(1);">
<div class="hero-logo"></div>
<p class="title"><bdo dir="ltr">A virtual projection<br>by Vincent Morisset</bdo></p>
<button class="box enter" dir="" style="transform: scale(1.001); -webkit-transform: scale(1.001);"><bdo dir="ltr">Start</bdo></button>
<p class="error-browser other" dir=""><bdo dir="ltr">Your web browser is not <br>supported by this experience. <br>Please try again using <a href="https://www.google.com/chrome">Google Chrome</a>.</bdo></p>
<p class="error-browser ff" dir=""><bdo dir="ltr">For the best performance, <br>we recommend <a href="https://www.google.com/chrome">Google Chrome</a>.</bdo></p>
</div>
<div class="link mouse-mode" dir=""><bdo dir="ltr">*No phone? <a>Use your mouse</a>.</bdo></div>
</div>
</section>
我不擅长 xpath,但为什么不使用 css 选择器呢?
driver.find_element_by_css_selector('button.box.enter').click()
您可以通过以下方式找到您的元素 XAPTH
。
element = driver.find_element_by_xpath('//button[@class="box enter" and contains(.,"Start")]')
element.click()
如何 select 'Start' 按钮并通过以下 HTML 代码单击它。
我想使用以下 python-selenium
库
喜欢:
driver.find_element_by_xpath('//div[contains(@class,"box enter")'
'and text() = "start"]').click()
HTML代码
<section class="LandingPageView shown" style="display: block;">
<div class="background"></div>
<div class="gradient"></div>
<div class="page" style="opacity: 1;">
<div class="background asset background-homepage"></div>
<div class="just-reflektor-link" style="width: 312.289575px; height: 381.447127941177px; right: 25.635%;"></div>
<div class="content" style="right: -14.3125px; margin-left: 0px; transform: scale(1); -webkit-transform: scale(1);">
<div class="hero-logo"></div>
<p class="title"><bdo dir="ltr">A virtual projection<br>by Vincent Morisset</bdo></p>
<button class="box enter" dir="" style="transform: scale(1.001); -webkit-transform: scale(1.001);"><bdo dir="ltr">Start</bdo></button>
<p class="error-browser other" dir=""><bdo dir="ltr">Your web browser is not <br>supported by this experience. <br>Please try again using <a href="https://www.google.com/chrome">Google Chrome</a>.</bdo></p>
<p class="error-browser ff" dir=""><bdo dir="ltr">For the best performance, <br>we recommend <a href="https://www.google.com/chrome">Google Chrome</a>.</bdo></p>
</div>
<div class="link mouse-mode" dir=""><bdo dir="ltr">*No phone? <a>Use your mouse</a>.</bdo></div>
</div>
</section>
我不擅长 xpath,但为什么不使用 css 选择器呢?
driver.find_element_by_css_selector('button.box.enter').click()
您可以通过以下方式找到您的元素 XAPTH
。
element = driver.find_element_by_xpath('//button[@class="box enter" and contains(.,"Start")]')
element.click()