繁体   English   中英

如何使用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

如何选择“开始”按钮,然后从以下HTML代码中单击它。 我想使用以下python-selenium lib Like做:

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查找元素的XAPTH

element = driver.find_element_by_xpath('//button[@class="box enter" and contains(.,"Start")]')
element.click()

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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