Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Seleniumbase element not located, despite valid XPATH. #3400

Answered by mdmintz
ZcodeZ777 asked this question in Q&A
Discussion options

I am currently writing a program which involves the following code:

with SB(uc=True, test=True, xvfb=True, incognito=True, agent=<user_agent>, headless=False) as sb:
 sb.activate_cdp_mode("https://invideo.io/perf/ga-ai-video-generator-web/?utm_source=google&utm_medium=cpc&utm_campaign=Top16_Search_Brand_Exact_EN&adset_name=InVideo&keyword=invideo&network=g&device=c&utm_term=invideo&utm_content=InVideo&matchtype=e&placement=g&campaign_id=18035330768&adset_id=140632017072&ad_id=616240030555&gad_source=1&gclid=Cj0KCQiAvvO7BhC-ARIsAGFyToWFf0L_8iqkB32qg9prKxVApsklZ8HA69LW2O0Z6XC1nbXXz9sCTTEaAinZEALw_wcB")
 sb.sleep(5)
 sb.cdp.find_element("//button[@class='iv-inline-block iv-text-body-xl md:iv-text-body-m iv-text-black-50 dark:iv-text-grey-30 iv-font-semibold iv-cursor-pointer']", timeout=600) # (very long timeout)

However, when I run this code, the element cannot be located (I have checked this XPATH numerous times and I can confirm it is valid), does anybody know what the issue could be?

You must be logged in to vote

Either directly use a CSS Selector, or make sure your XPath class doesn't contain special characters, such as :.
Your XPath class had : twice: In md:iv-text-body-m, and in dark:iv-text-grey-30.

It all gets converted into CSS anyway. Because class segment order can change, a class like "part1 part2 part3" gets converted into dot-notation like this: ".part1.part2.part3".

Therefore, sb.cdp.find_element('//button[@class="iv-inline-block iv-text-body-xl iv-text-black-50 iv-font-semibold iv-cursor-pointer"]') works because the class segments with : were removed.

Replies: 1 comment

Comment options

Either directly use a CSS Selector, or make sure your XPath class doesn't contain special characters, such as :.
Your XPath class had : twice: In md:iv-text-body-m, and in dark:iv-text-grey-30.

It all gets converted into CSS anyway. Because class segment order can change, a class like "part1 part2 part3" gets converted into dot-notation like this: ".part1.part2.part3".

Therefore, sb.cdp.find_element('//button[@class="iv-inline-block iv-text-body-xl iv-text-black-50 iv-font-semibold iv-cursor-pointer"]') works because the class segments with : were removed.

You must be logged in to vote
0 replies
Answer selected by mdmintz
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet

AltStyle によって変換されたページ (->オリジナル) /