How to find the element from the HTML provided through Selenium and Python?

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP



How to find the element from the HTML provided through Selenium and Python?



Actually this button is located inside container. Please provide syntax for python
Here this property has unique name, but dont know how to use this [data-control-name="job_search_category_suggestion_it"]


[data-control-name="job_search_category_suggestion_it"]


<button class="jobs-search-category-suggestions__button button-secondary-medium-muted mb2 mr2" data-control-name="job_search_category_suggestion_it" data-ember-action="" data-ember-action-8126="8126">
<li-icon aria-hidden="true" type="search-icon" size="small"><svg viewBox="0 0 24 24" width="24px" height="24px" x="0" y="0" preserveAspectRatio="xMinYMin meet" class="artdeco-icon" focusable="false"><path d="M14,12.67L11.13,9.8A5,5,0,1,0,9.8,11.13L12.67,14ZM3.88,7A3.13,3.13,0,1,1,7,10.13,3.13,3.13,0,0,1,3.88,7Z" class="small-icon" style="fill-opacity: 1"></path></svg></li-icon>IT
</button>



I used this code:


elem = driver.find_elements_by_xpath('//button[@data-control-name="job_search_category_suggestion_it]').click()




1 Answer
1



As per the HTML you have shared the desired element is dynamic, so you need to induce WebDriverWait for the element to be clickable and you can use the following solution:


WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//button[@class='jobs-search-category-suggestions__button button-secondary-medium-muted mb2 mr2'][contains(.,'IT')]"))).click()



Note : You have to add the following imports :


from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

Firebase Auth - with Email and Password - Check user already registered

Dynamically update html content plain JS

Creating a leaderboard in HTML/JS