So im making a script that clicks some buttons for me in a web browser.
Importing the selenium driver:
from selenium import webdriver
browser = webdriver.Chrome(executable_path=r'C:/Python27/Scripts/chromedriver.exe')
In this example, When i want to click on the "leave hotel" button, i can just use the css_selector and it works fine.
<div id="canvas">
<!--<a onclick="leave_hotel();" name="go_ut" onmousedown="signature.push([Math.floor(Date.now()), 'click']);" class="hotel-button-out">-->
<a onclick="leave_hotel();" name="go_ut" onmousedown="" class="hotel-button-out">Sjekk ut <span style="font-size:0.7em" id="hotell_tid">(23 t 55 m)</span></a>
<input type="hidden" name="t" value="cb5a965fbb0a3578344aec059afa7246">
<input type="hidden" name="xy" id="xy" value="">
<input type="hidden" name="ltoken" value="ea782433046a2e254b10db5045b55d02">
<input type="hidden" value="633eacc2bbe92004ba03c9dd57ff9457" name="ttoken">
<input type="hidden" name="jtoken" id="jtoken" value="">
</div>
Something like this worked fine:
browser.find_element_by_css_selector('#canvas > a').click()
But when i try to click a button within a div on another page, it does not work. the html looks like this:
<div class="canvas hotel-out">
<input class=" btn btn-block" name="enkel_knapp" onmousedown="krim_enkel_bego(2);" type="button" id="submit" value="Begå kriminaliteten!">
<input type="hidden" name="ltoken" value="e386d141ff442655d48275e0269fe1fe">
<input type="hidden" value="2b61bc54fe84d18ae5ad797826152e32" name="ttoken">
<input type="hidden" name="jtoken" id="jtoken" value="">
<input type="hidden" id="xy" value="nytt system (ingen koordinater)" name="xy">
</div>
But the problem is that the buttons xpath is simliar to 3 other buttons. all three buttons got the xpath "//*[@id="submit"]". I guess there is some kind of conflict here?
When i try to do it by name like this i get no respose:
browser.find_element_by_name('enkel_knapp').click()
Nothing when i do it by ID either:
browser.find_element_by_id('submit').click()
Anyone got any tips to filter by div or something?
The error i get: Pastebin