-
Notifications
You must be signed in to change notification settings - Fork 1.4k
-
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?
Beta Was this translation helpful? Give feedback.
All reactions
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
-
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.
Beta Was this translation helpful? Give feedback.