Closed Jamadoo closed 4 months ago
@Jamadoo I have bad news, the problem seems to have persisted. I passed in @bbc and it uploaded with something totally wrong
You can see the username that it ended up uploading:
what seems strange is the first user in the list of user which tiktok gives is anthony... How the hell does tiktok get that?? The username string is the username of the first div child, aka the top user in the list then the search string is the user we are looking for.
And as we can see in your screenshot, tiktok put "anthony" as the top user... That seems like a tiktok problem not a code problem?
@Jamadoo I know right I think his username has TikTok in it and they match both when searching
@callum-fortune but thats suppose to be a issue on tiktok's side? What we can do is, we loop through all the children of the div. Check the username. If the user-ids match, we click the element. And after 5 seconds, we just press enter to select the first element
What happened in your test with the new code?
@Jamadoo This time I got @cooplive returned lol. Not sure whats going on, I'm debugging it now
@callum-fortune are you running on normal mod (not headless)? What does tiktok give in the list of usernames when the bot enters bbc?
@Jamadoo Yeh I'm not running headless at the moment so I can see whats happening. Initially it was giving random users that I follow so i added a time.sleep between sending the space and backspace. Then it started returning bbc accounts but still selected @bbcnews instead of @bbc. Weird...
try increasing the timeout to like 30 secs and remove your sleep. See if the users get updated
i created the code which loops through all the shown users. Im testing it rn
@Jamadoo I was literally just coming to say that, you were only checking the first user
i think i got it wokring. Still debugging @callum-fortune
@Jamadoo I think the reason you couldn't reproduce is because the top recommendations are people that you follow, I assume you are using a tiktok account that follows nobody but I follow many people.
A also have a solution that appears to work, will be interesting to see how they compare π
@callum-fortune yes, exactly. Im using a account with no followers. I could quickly test with my main
What your solution?
@Jamadoo My solution counts the iterations in the loop and when it finds the correct match, it sends the down key that many times to navigate down the dropdown and select the correct user
@callum-fortune Im simply getting all the user-id classes and looping through them. Heres my code
elif word[0] == "@":
logger.debug(green('- Adding Mention: ' + word))
desc.send_keys(word)
desc.send_keys(' ' + Keys.BACKSPACE)
# Wait For Popup
Popup = driverWait.until(EC.presence_of_element_located(
(By.XPATH, config['selectors']['upload']['mention_box'])
))
# Wait For Div With Users
Div = driverWait.until(
lambda driver: Popup.find_element(By.XPATH, "./div[not(@*)]")
)
# Wait until it has at least two children
driverWait.until(
lambda driver: len(Div.find_elements(By.XPATH, "./*")) >= 2
)
## Wait For Correct User To Appear
# Variable indicating whether the loop should continue
found = False
waiting_interval = 0.5
timeout = 5
start_time = time.time()
# Loop until the desired condition is met
while not found and (time.time() - start_time < timeout):
# Get all children with 'user-id' class
user_id_elements = Div.find_elements(By.CLASS_NAME, "user-id")
for user_id_element in user_id_elements:
if user_id_element and user_id_element.is_enabled:
# If elements are found, check the first one
first_user_id = user_id_elements[0]
# Get the inner text
first_user_id_text = first_user_id.text
username = first_user_id_text.split(" Β· ")[0]
# Compare with the target word
if username.lower() == word[1:].lower():
found = True
user_id_element.click()
print("Matching User found : Clicking User")
break
if not found:
# If not matching, wait and repeat
print(f"No match. Waiting for {waiting_interval} seconds...")
time.sleep(waiting_interval) # Pause for the specified interval
if not found:
logger.debug(green('- Selecting First User'))
desc.send_keys(Keys.ENTER)
@Jamadoo My solution counts the iterations in the loop and when it finds the correct match, it sends the down key that many times to navigate down the dropdown and select the correct user
so you loop through the user-id and count how many down is the needed user and the press down arrow that many times? Im geussing you dont know you can just click that element, right? π
@Jamadoo Its getting late ok lmao. Nah I didn't realise the actual element object was being passed down so didn't think to click it
@callum-fortune dont worry, its also 10pm for me
im starting to loose all my focus as well π
last test run, then i need to do some work for my classes tmr. And also summarize the last couple pages of science chapter for tmr π
@Jamadoo Where are you actually located? its 9pm here. I'm just implementing your code on my side and I'll get it all cleaned up and pushed to that PR
@callum-fortune Im from South Africa. and u?
Great, so im guessing the script works for situation?
@Jamadoo I'm in the UK. Yeh it pretty much works now just a few touches, I'll make sure to co-author you in the PR
i just tested the script on my main, works like excepted as well. I did notice my US account and SA account's UI was different. That could also be a factor for why random users popup for you. @callum-fortune
@Jamadoo I'm in the UK. Yeh it pretty much works now just a few touches, I'll make sure to co-author you in the PR
alright, sounds good. Thanks for your help. Ima leave the rest to you
@Jamadoo Cheers, have a good one!
@callum-fortune Thanks, you to π»
This is a issue relating to @callum-fortune 's new Pull-Request
On Lines
If the title of the file is longer then the half of the text box, only the text before the half of the text box is removed. Considor sending "Keys.End" before calling clear
Works great in my experience.
I also noticed a log is send in the console of the browser ({isSameSearchValue: false}) each time the dialog pops up showcasing the available hashtags and mentions. We could use a wait until this log gets written instead of