Hello Amir,
You are still required to spend some more time on finding the css and xpath locator.
Below are some of the improvements which are required.
1. CSS which was used is incorrect instead of this -"driver.find_element_by_css_selector('button.ScCoreButton-sc-1qn4ixc-0 ScCoreButtonPrimary-sc-1qn4ixc-1 jCxFvU tw-core-button')" it should have been this - "driver.find_element_by_css_selector('button.ScCoreButton-sc-1qn4ixc-0.ScCoreButtonPrimary-sc-1qn4ixc-1.jCxFvU.tw-core-button')". // please notice that spaces are replaced with dot(.)
2. Xpath written in incorrect - you have put the extra space at the beginning of class name. It should be -
xpath= //button[@class="ScCoreButton-sc-1qn4ixc-0 ScCoreButtonPrimary-sc-1qn4ixc-1 jCxFvU tw-core-button"]
Post identifying the locator you can cross check the locator using develop tool itself :
Developer tool-> Elements-> CNTRL+F -> paste the locator(xpath, css ...) -> if that is valid locator then you will be able to find the number matching nodes as shown in the below image
I could see that you are trying to locate the follow button, below are the few locators which can be used for locating follow btn.
-> xpath= //button[@class="ScCoreButton-sc-1qn4ixc-0 ScCoreButtonPrimary-sc-1qn4ixc-1 jCxFvU tw-core-button"] // mose likely to fail in long run because of the dynamic class name value
xpath= //button[@data-test-selector="follow-button"]
xpath = //*[contains(text(),'Follow')]
xpath= //div[@class='follow-btn__follow-btn']//button
-> css = button.ScCoreButton-sc-1qn4ixc-0.ScCoreButtonPrimary-sc-1qn4ixc-1.jCxFvU.tw-core-button //
/ mose likely to fail in long run
css = button[class='ScCoreButton-sc-1qn4ixc-0 ScCoreButtonPrimary-sc-1qn4ixc-1 jCxFvU tw-core-button']
css= div.follow-btn__follow-btn
Now, let's assume you wanna locate the search symbol which is at the top centre near to search into field, using the xpath "//button" I could see that there are 33 matching nodes available. We should look for some other properties (either to the parent or child nodes of the current element) which are unique for a given element. If we try to look at the some of parent nodes I could see that unique node "//div[@class='search-box']", once you are unique node you can create your locator using the same like this "//div[@class='search-box']//button".
There are multiple other ways to locate the element which probably you can learn on the go.
Regards,
Arvind Sah