Check box has different xpath for Chrome (Version 81.0.4044.138) and Firefox (76.0.1 (64-bit)), It works for one at a time | Selenium Python Forum
K
Kam Posted on 16/05/2020

Check box has different xpath for Chrome (Version 81.0.4044.138) and Firefox (76.0.1 (64-bit)), It works for one at a time

Getting error:

 

============================= test session starts =============================

platform win32 -- Python 3.7.4, pytest-5.4.1, py-1.8.1, pluggy-0.13.1

rootdir: C:\eclipse-workspace2\Hybrid-Framework

plugins: allure-pytest-2.8.13

collected 3 items

 

Testcases\test_login.py sF

INTERNALERROR> Traceback (most recent call last):

INTERNALERROR>   File "C:\Users\Owner\AppData\Local\Programs\Python\Python37\lib\site-packages\_pytest\main.py", line 191, in wrap_session

INTERNALERROR>     session.exitstatus = doit(config, session) or 0

INTERNALERROR>   File "C:\Users\Owner\AppData\Local\Programs\Python\Python37\lib\site-packages\_pytest\main.py", line 247, in _main

INTERNALERROR>     config.hook.pytest_runtestloop(session=session)

INTERNALERROR>   File "C:\Users\Owner\AppData\Local\Programs\Python\Python37\lib\site-packages\pluggy\hooks.py", line 286, in __call__

INTERNALERROR>     return self._hookexec(self, self.get_hookimpls(), kwargs)

INTERNALERROR>   File "C:\Users\Owner\AppData\Local\Programs\Python\Python37\lib\site-packages\pluggy\manager.py", line 93, in _hookexec

INTERNALERROR>     return self._inner_hookexec(hook, methods, kwargs)

INTERNALERROR>   File "C:\Users\Owner\AppData\Local\Programs\Python\Python37\lib\site-packages\pluggy\manager.py", line 87, in <lambda>

INTERNALERROR>     firstresult=hook.spec.opts.get("firstresult") if hook.spec else False,

INTERNALERROR>   File "C:\Users\Owner\AppData\Local\Programs\Python\Python37\lib\site-packages\pluggy\callers.py", line 208, in _multicall

INTERNALERROR>     return outcome.get_result()

INTERNALERROR>   File "C:\Users\Owner\AppData\Local\Programs\Python\Python37\lib\site-packages\pluggy\callers.py", line 80, in get_result

INTERNALERROR>     raise ex[1].with_traceback(ex[2])

INTERNALERROR>   File "C:\Users\Owner\AppData\Local\Programs\Python\Python37\lib\site-packages\pluggy\callers.py", line 187, in _multicall

INTERNALERROR>     res = hook_impl.function(*args)

INTERNALERROR>   File "C:\Users\Owner\AppData\Local\Programs\Python\Python37\lib\site-packages\_pytest\main.py", line 272, in pytest_runtestloop

INTERNALERROR>     item.config.hook.pytest_runtest_protocol(item=item, nextitem=nextitem)

INTERNALERROR>   File "C:\Users\Owner\AppData\Local\Programs\Python\Python37\lib\site-packages\pluggy\hooks.py", line 286, in __call__

INTERNALERROR>     return self._hookexec(self, self.get_hookimpls(), kwargs)

INTERNALERROR>   File "C:\Users\Owner\AppData\Local\Programs\Python\Python37\lib\site-packages\pluggy\manager.py", line 93, in _hookexec

INTERNALERROR>     return self._inner_hookexec(hook, methods, kwargs)

INTERNALERROR>   File "C:\Users\Owner\AppData\Local\Programs\Python\Python37\lib\site-packages\pluggy\manager.py", line 87, in <lambda>

INTERNALERROR>     firstresult=hook.spec.opts.get("firstresult") if hook.spec else False,

INTERNALERROR>   File "C:\Users\Owner\AppData\Local\Programs\Python\Python37\lib\site-packages\pluggy\callers.py", line 208, in _multicall

INTERNALERROR>     return outcome.get_result()

INTERNALERROR>   File "C:\Users\Owner\AppData\Local\Programs\Python\Python37\lib\site-packages\pluggy\callers.py", line 80, in get_result

INTERNALERROR>     raise ex[1].with_traceback(ex[2])

INTERNALERROR>   File "C:\Users\Owner\AppData\Local\Programs\Python\Python37\lib\site-packages\pluggy\callers.py", line 187, in _multicall

INTERNALERROR>     res = hook_impl.function(*args)

INTERNALERROR>   File "C:\Users\Owner\AppData\Local\Programs\Python\Python37\lib\site-packages\_pytest\runner.py", line 85, in pytest_runtest_protocol

INTERNALERROR>     runtestprotocol(item, nextitem=nextitem)

INTERNALERROR>   File "C:\Users\Owner\AppData\Local\Programs\Python\Python37\lib\site-packages\_pytest\runner.py", line 100, in runtestprotocol

INTERNALERROR>     reports.append(call_and_report(item, "call", log))

INTERNALERROR>   File "C:\Users\Owner\AppData\Local\Programs\Python\Python37\lib\site-packages\_pytest\runner.py", line 190, in call_and_report

INTERNALERROR>     hook.pytest_runtest_logreport(report=report)

INTERNALERROR>   File "C:\Users\Owner\AppData\Local\Programs\Python\Python37\lib\site-packages\pluggy\hooks.py", line 286, in __call__

INTERNALERROR>     return self._hookexec(self, self.get_hookimpls(), kwargs)

INTERNALERROR>   File "C:\Users\Owner\AppData\Local\Programs\Python\Python37\lib\site-packages\pluggy\manager.py", line 93, in _hookexec

INTERNALERROR>     return self._inner_hookexec(hook, methods, kwargs)

INTERNALERROR>   File "C:\Users\Owner\AppData\Local\Programs\Python\Python37\lib\site-packages\pluggy\manager.py", line 87, in <lambda>

INTERNALERROR>     firstresult=hook.spec.opts.get("firstresult") if hook.spec else False,

INTERNALERROR>   File "C:\Users\Owner\AppData\Local\Programs\Python\Python37\lib\site-packages\pluggy\callers.py", line 208, in _multicall

INTERNALERROR>     return outcome.get_result()

INTERNALERROR>   File "C:\Users\Owner\AppData\Local\Programs\Python\Python37\lib\site-packages\pluggy\callers.py", line 80, in get_result

INTERNALERROR>     raise ex[1].with_traceback(ex[2])

INTERNALERROR>   File "C:\Users\Owner\AppData\Local\Programs\Python\Python37\lib\site-packages\pluggy\callers.py", line 187, in _multicall

INTERNALERROR>     res = hook_impl.function(*args)

INTERNALERROR>   File "C:\Users\Owner\.p2\pool\plugins\org.python.pydev.core_7.5.0.202001101138\pysrc\_pydev_runfiles\pydev_runfiles_pytest2.py", line 243, in pytest_runtest_logreport

INTERNALERROR>     exc = _get_error_contents_from_report(report)

INTERNALERROR>   File "C:\Users\Owner\.p2\pool\plugins\org.python.pydev.core_7.5.0.202001101138\pysrc\_pydev_runfiles\pydev_runfiles_pytest2.py", line 147, in _get_error_contents_from_report

INTERNALERROR>     report.toterminal(tw)

INTERNALERROR>   File "C:\Users\Owner\AppData\Local\Programs\Python\Python37\lib\site-packages\_pytest\reports.py", line 65, in toterminal

INTERNALERROR>     longrepr.toterminal(out)

INTERNALERROR>   File "C:\Users\Owner\AppData\Local\Programs\Python\Python37\lib\site-packages\_pytest\_code\code.py", line 962, in toterminal

INTERNALERROR>     element[0].toterminal(tw)

INTERNALERROR>   File "C:\Users\Owner\AppData\Local\Programs\Python\Python37\lib\site-packages\_pytest\_code\code.py", line 992, in toterminal

INTERNALERROR>     entry.toterminal(tw)

INTERNALERROR>   File "C:\Users\Owner\AppData\Local\Programs\Python\Python37\lib\site-packages\_pytest\_code\code.py", line 1080, in toterminal

INTERNALERROR>     self._write_entry_lines(tw)

INTERNALERROR>   File "C:\Users\Owner\AppData\Local\Programs\Python\Python37\lib\site-packages\_pytest\_code\code.py", line 1062, in _write_entry_lines

INTERNALERROR>     tw._write_source(source_lines, indents)

INTERNALERROR> AttributeError: 'TerminalWriter' object has no attribute '_write_source'

 

======================== 1 failed, 1 skipped in 47.12s ========================

 

 

HTML:

 

GOOGLE CHROM:

 

Mozill:

 

 

 

XPATH for CHROME:

checkbox_xpath = //*[@id="signupform"]/div/div[6]/div[2]/label/span

XPATH FOR MOZILLA:

checkbox_xpath = //*[@id="signupform"]/div/div[6]/div[2]/label/input

 

I use OR option and is NOT working

 


K
Kam Replied on 18/05/2020

ANY UPDATE?

I am looking xpath which can work with all browsers


0
09914040666 Replied on 19/05/2020

Hey, 

Can you please share the URL of the site you are working on so that it may be checked.


K
Kam Replied on 20/05/2020

0
09914040666 Replied on 20/05/2020

Hey, 

The checkbox you are using is having the id : "signup-termservice" so either try using the id directly or use the xpath

"//*[@id='signup-termservice']"


K
Kam Replied on 20/05/2020

Thats not my question.

I am asking same xpath is NOT working for Chrome and Firefox. I have to use different xpath. Did you look "//*[@id='signup-termservice']" os working for both. 

 


M
Replied on 22/05/2020

Hey, please try the code below it is fully functional on both chrome and firefox. 

from selenium import webdriver
import time
def test_try():
driver = webdriver.Firefox()
driver.get("https://www.zoho.com/")
driver.find_element_by_xpath("/html/body/div[3]/div[2]/div/a[5]").click()
driver.find_element_by_name("email").send_keys("ghh")
driver.find_element_by_xpath("//input[@id='tos']").click()


0
09914040666 Replied on 22/05/2020

Hey, please try the code below it is fully functional on both chrome and firefox. 

from selenium import webdriver
import time
def test_try():
driver = webdriver.Firefox()
driver.get("https://www.zoho.com/")
driver.find_element_by_xpath("/html/body/div[3]/div[2]/div/a[5]").click()
driver.find_element_by_name("email").send_keys("ghh")
driver.find_element_by_xpath("//input[@id='tos']").click()


K
Kam Replied on 26/05/2020

Is NOT working on both Browsers Chrome and FIREFOX. I am looking one xpath for both browsers :


#selenium.common.exceptions.ElementClickInterceptedException: Message: Element <span id="signup-termservice" class="unchecked"> is not clickable at point (385,434) because another element <input id="tos" class="za-tos" name="tos" type="checkbox"> obscures it

#C:\Users\Owner\AppData\Local\Programs\Python\Python37\lib\site-packages\selenium\webdriver\remote\errorhandler.py:242: ElementClickInterceptedException


# selenium.common.exceptions.ElementClickInterceptedException: Message: element click intercepted: Element <input tabindex="1" class="za-tos" id="tos" name="tos" value="false" onclick="toggleTosField()" type="checkbox"> is not clickable at point (259, 420). Other element would receive the click: <div class="signup-form">...</div>


0
09914040666 Replied on 28/05/2020

Hey, 

The error you are facing is because the element which you want to use takes some time to be enabled and become ready to use, so you may try using the explicit wait method or the code in the file attached.

The code is going to wait dynamically for 10 seconds until the element is enabled, once the element is enabled the loop will break.

 


Related Posts