0

I tried so many ways to click something on a website but it couldn't work.

Here is the HTML code:

<a href="javascript:void(0);" class="ui-btn">一次付清</a>

I tried to use xpath to locate the element but it didn't work

driver.find_element_by_xpath("/html/body/div[1]/div[2]/div/div/div[2]/dl[1]/dd/ul/li[1]/a").click()
Tim
  • 1
  • 1
  • Hello! Could you please provide your source code, Thanks! – Ice Bear Dec 17 '20 at 04:12
  • Hello! I just updated the question. Thank you for your help! – Tim Dec 17 '20 at 04:31
  • May I ask the `a` tag really doesn't have a `href` attribute? cause if it has and you are trying to go to that site, you can simply just get the value of `href` and do a `driver.get(url)`. If that's not the cause I suggest this [Selenium Driver Wait](https://stackoverflow.com/questions/26566799/wait-until-page-is-loaded-with-selenium-webdriver-for-python) – Ice Bear Dec 17 '20 at 04:36
  • I dont think there is a tag. I have tried driver wait method but I cant locate the element. – Tim Dec 17 '20 at 04:44
  • 1
    Could you also put the `error` message if any & possible the at least the sample `html` code cause what I think is two things 1.) What the error message says 2.) Probably you might have to review your `xpath`. – Ice Bear Dec 17 '20 at 04:52
  • Message: no such element: Unable to locate element: {"method":"xpath","selector":"/html/body/div[1]/div[2]/div/div/div[2]/dl[1]/dd/ul/li[1]/a"} (Session info: chrome=87.0.4280.88) – Tim Dec 17 '20 at 04:58
  • Xpath is evil try ```CSS selectors``` or ```class selectors```. like ```driver.find_element_by_css_selector(".ui-btn")``` or ```driver.find_element_by_class_name("ui-btn")``` – Sajid Dec 17 '20 at 05:39
  • There are multiples un-btn on the html. I am thinking how to add the chinese characters in CSS selectors. Thanks – Tim Dec 17 '20 at 06:05

0 Answers0