1

My goal: is to automate a boring task on github

What: I want to click on "add file" and than "create new file" enter image description here

I am not sure how to get the element without an id enter image description here

1
  • Use driver.find_element_by_class_name Commented Dec 15, 2020 at 4:08

3 Answers 3

1

If no id or the element has dynamic id, use XPATH. Using class is not ideal, since the class will possibly reused by many other elements.

In this case, use this XPATH: //summary[.//span[contains(text(),"Add file")]]

Best practice: use fluent wait

WebDriverWait(driver, 15).until(
        EC.visibility_of_element_located(
                (By.XPATH, '//summary[.//span[contains(text(),"Add file")]]')
        ))

Read docs about explicit/fluent wait: https://selenium-python.readthedocs.io/waits.html#explicit-waits

Sign up to request clarification or add additional context in comments.

Comments

0

You could try driver.find_element_by_xpath("[xpath goes here]")

If you want to read more, here are the official docs for locating elements.

Comments

0
from selenium import webdirver

#define your executable path 
browser = webdriver.Chrome(executable path="  ") 
browser.get("**")
browser.find_element_by_xpath("put your copied xpath here")

1 Comment

you can also use by_class

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.