Home > Software engineering >  Selenium unable to locate xpath however the xpath is there in the browser
Selenium unable to locate xpath however the xpath is there in the browser

Time:12-09

Im not sure if that was quite the best title but Im not sure how else to describe it, I am trying to use selenium to automate 2fa on a website so all I need to do is anwser the phone call and the script will take care of the rest however the button I am trying to get selenium to click keeps showing up as unable to locate even though its always in the same place and never changes here is my code in python

callMe = driver.find_element('xpath', '//*[@id="auth_methods"]/fieldset/div[2]/button')
callMe.click()
sleep(25)

this is one of three buttons that all have the same element information besides the xpaths here are all 3 button elements I am trying to grab the second one

<button tabindex="2" type="submit" ><!-- -->Send Me a Push </button>
<button tabindex="2" type="submit" ><!-- -->Call Me </button>
<button tabindex="2" type="submit" ><!-- -->Text Me </button>

I am not sure how else I can locate the second button besides using the xpath but that is not working and I dont know if I can or how I can search for the button based off the text that is inside it.

CodePudding user response:

Did you try with By ?

from selenium.webdriver.common.by import By

callMe = driver.find_element(By.XPATH, '//*[@id="auth_methods"]/fieldset/div[2]/button')

CodePudding user response:

Try using By.cssselector, get the css selector of the main body html for the button you want.

callMe = driver.find_element(By.css_selector, 'selectorofbodyhtml')
callme.click()
  • Related