简体   繁体   中英

How to select 'Start' button and click it from following HTML code by using find_element_by_xpath or selenium-python API

How to select 'Start' button and click it from following HTML code. I would like to do using following python-selenium lib Like:

driver.find_element_by_xpath('//div[contains(@class,"box enter")' 
                                         'and text() = "start"]').click()

HTML Code

<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()

Here is how you can find your element via XAPTH .

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

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